Skip to content

Commit

Permalink
More benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 18, 2024
1 parent 099f4db commit b8a52bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ chacha20 x 1,506,024 ops/sec @ 664ns/op
xchacha20 x 1,064,962 ops/sec @ 939ns/op
chacha8 x 1,683,501 ops/sec @ 594ns/op
chacha12 x 1,628,664 ops/sec @ 614ns/op
aes-256-ecb x 775,193 ops/sec @ 1μs/op
aes-256-cbc x 738,552 ops/sec @ 1μs/op
aes-256-ctr x 737,463 ops/sec @ 1μs/op
aes-ecb-256 x 775,193 ops/sec @ 1μs/op
aes-cbc-256 x 738,552 ops/sec @ 1μs/op
aes-ctr-256 x 737,463 ops/sec @ 1μs/op
1MB
xsalsa20poly1305 x 205 ops/sec @ 4ms/op
Expand All @@ -500,10 +500,10 @@ chacha20 x 506 ops/sec @ 1ms/op
xchacha20 x 506 ops/sec @ 1ms/op
chacha8 x 956 ops/sec @ 1ms/op
chacha12 x 735 ops/sec @ 1ms/op
aes-256-ecb x 229 ops/sec @ 4ms/op
aes-256-cbc x 110 ops/sec @ 9ms/op
aes-256-ctr x 115 ops/sec @ 8ms/op
# Wrapper over built-in webcrypto
webcrypto ctr-256 x 5,068 ops/sec @ 197μs/op
webcrypto cbc-256 x 1,116 ops/sec @ 895μs/op
webcrypto gcm-256 x 4,374 ops/sec @ 228μs/op ± 1.69% [172μs..7ms]
```

Compare to other implementations:
Expand Down
17 changes: 12 additions & 5 deletions benchmark/noble.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { mark } from 'micro-bmark';
import { buf } from './_utils.js';
import { concatBytes } from '@noble/ciphers/utils';
import { xsalsa20poly1305 } from '@noble/ciphers/salsa';
import { xchacha20poly1305, chacha20poly1305 } from '@noble/ciphers/chacha';
import { salsa20, xsalsa20 } from '@noble/ciphers/salsa';
import { chacha20, xchacha20, chacha8, chacha12 } from '@noble/ciphers/chacha';
import { ecb, ctr, cbc, gcm, siv } from '@noble/ciphers/aes';
import * as aesw from '@noble/ciphers/webcrypto';

const buffers = [
// { size: '16B', samples: 1_500_000, data: buf(16) }, // common block size
{ size: '32B', samples: 1_500_000, data: buf(32) },
// { size: '32B', samples: 1_500_000, data: buf(32) },
{ size: '64B', samples: 1_000_000, data: buf(64) },
// { size: '1KB', samples: 50_000, data: buf(1024) },
// { size: '8KB', samples: 10_000, data: buf(1024 * 8) },
Expand Down Expand Up @@ -38,9 +38,16 @@ async function main() {
await mark('xchacha20', i, () => xchacha20(key, nonce24, buf));
await mark('chacha8', i, () => chacha8(key, nonce, buf));
await mark('chacha12', i, () => chacha12(key, nonce, buf));
await mark('aes-256-ecb', i, () => ecb(key).encrypt(buf));
await mark('aes-256-cbc', i, () => cbc(key, nonce16).encrypt(buf));
await mark('aes-256-ctr', i, () => ctr(key, nonce16).encrypt(buf));
await mark('aes-ecb-256', i, () => ecb(key).encrypt(buf));
await mark('aes-cbc-256', i, () => cbc(key, nonce16).encrypt(buf));
await mark('aes-ctr-256', i, () => ctr(key, nonce16).encrypt(buf));

if (size === '1MB') {
console.log('# Wrapper over built-in webcrypto');
await mark('webcrypto ctr-256', 5000, () => aesw.ctr(key, nonce16).encrypt(buf));
await mark('webcrypto cbc-256', 5000, () => aesw.cbc(key, nonce16).encrypt(buf));
await mark('webcrypto gcm-256', 5000, () => aesw.gcm(key, nonce).encrypt(buf));
}
console.log();
}
}
Expand Down

0 comments on commit b8a52bb

Please sign in to comment.