Skip to content

Commit

Permalink
make encryption perf test configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed May 23, 2023
1 parent bd59307 commit 783af8c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crypto.test.js
Expand Up @@ -118,6 +118,8 @@ export const testImportExport = async tc => {
* @param {t.TestCase} tc
*/
export const testEncryptionPerformance = async tc => {
const N = 1000
const BLen = 1000
const secret = prng.word(tc.prng, 1, 30)
const salt = prng.word(tc.prng)
/**
Expand All @@ -131,14 +133,14 @@ export const testEncryptionPerformance = async tc => {
* @type {Array<Uint8Array>}
*/
const data = []
for (let i = 0; i < 1000; i++) {
data.push(webcrypto.getRandomValues(new Uint8Array(1000)))
for (let i = 0; i < N; i++) {
data.push(webcrypto.getRandomValues(new Uint8Array(BLen)))
}
/**
* @type {Array<Uint8Array>}
*/
const encryptedData = []
await t.measureTimeAsync('Encrypt 1k blocks of size 1kb', async () => {
await t.measureTimeAsync(`Encrypt ${N / 1000}k blocks of size ${BLen}byte`, async () => {
for (let i = 0; i < data.length; i++) {
encryptedData.push(await aes.encrypt(key, data[i]))
}
Expand All @@ -147,7 +149,7 @@ export const testEncryptionPerformance = async tc => {
* @type {Array<Uint8Array>}
*/
const decryptedData = []
await t.measureTimeAsync('Decrypt 1k blocks of size 1kb', async () => {
await t.measureTimeAsync(`Decrypt ${N / 1000}k blocks of size ${BLen}byte`, async () => {
for (let i = 0; i < encryptedData.length; i++) {
decryptedData.push(await aes.decrypt(key, encryptedData[i]))
}
Expand Down

0 comments on commit 783af8c

Please sign in to comment.