mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-03-30 15:08:32 +00:00
Add time benchmark test for streamed sign (testing hashing performance)
This commit is contained in:
parent
2377b2958d
commit
6d477ea509
@ -1,4 +1,5 @@
|
||||
import Benchmark from 'benchmark';
|
||||
import { readToEnd } from '@openpgp/web-stream-tools';
|
||||
import * as openpgp from 'openpgp';
|
||||
|
||||
const wrapAsync = func => ({
|
||||
@ -25,6 +26,22 @@ const onError = err => {
|
||||
(async () => {
|
||||
const suite = new Benchmark.Suite();
|
||||
const { armoredKey, privateKey, publicKey, armoredEncryptedMessage, armoredSignedMessage } = await getTestData();
|
||||
function* largeDataGenerator({ chunk, numberOfChunks }) {
|
||||
for (let chunkNumber = 0; chunkNumber < numberOfChunks; chunkNumber++) {
|
||||
yield chunk;
|
||||
}
|
||||
}
|
||||
|
||||
const streamFromGenerator = it => new ReadableStream({
|
||||
pull: controller => {
|
||||
const { value, done } = it.next();
|
||||
if (done) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.enqueue(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
suite.add('openpgp.readKey', wrapAsync(async () => {
|
||||
await openpgp.readKey({ armoredKey });
|
||||
@ -48,6 +65,14 @@ const onError = err => {
|
||||
await openpgp.sign({ message, signingKeys: privateKey });
|
||||
}));
|
||||
|
||||
suite.add('openpgp.sign (stream)', wrapAsync(async () => {
|
||||
const inputStream = streamFromGenerator(largeDataGenerator({ chunk: new Uint8Array(10000), numberOfChunks: 10 }));
|
||||
const message = await openpgp.createMessage({ binary: inputStream });
|
||||
const signed = await openpgp.sign({ message, signingKeys: privateKey });
|
||||
|
||||
await readToEnd(signed);
|
||||
}));
|
||||
|
||||
suite.add('openpgp.decrypt', wrapAsync(async () => {
|
||||
const message = await openpgp.readMessage({ armoredMessage: armoredEncryptedMessage });
|
||||
await openpgp.decrypt({ message, decryptionKeys: privateKey });
|
||||
|
Loading…
x
Reference in New Issue
Block a user