diff --git a/src/benchmarks.ts b/src/benchmarks.ts index 5c0be80..0059a76 100644 --- a/src/benchmarks.ts +++ b/src/benchmarks.ts @@ -25,13 +25,23 @@ export function testJson(testData: any): Promise { export function testJsonUnmapped(testData: any): Promise { return benchmark({ data: testData, - encode: data => JSON.stringify(data), - decode: data => JSON.parse(data), - sampleDecoded: data => data[0], + encode: (data) => JSON.stringify(data), + decode: (data) => JSON.parse(data), + sampleDecoded: (data) => data[0], encoding: 'utf8', }); } +export function testV8Serialize(testData: any): Promise { + const v8 = require('v8'); + return benchmark({ + data: testData, + encode: (data) => v8.serialize(data), + decode: (data) => v8.deserialize(data), + sampleDecoded: (data) => data.items[0], + }); +} + function createAvroSchemaBase(): any { return { name: 'items', diff --git a/src/index.ts b/src/index.ts index 33faeba..702bd36 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,17 @@ import * as bench from './benchmarks'; import { runTest } from './utils/helper'; - const TESTS = { testJson: () => runTest('JSON', ({ data }) => bench.testJson(data), 298), + testV8Serialize: () => runTest('V8 Serialize', ({ data }) => bench.testV8Serialize(data), 298), + testBson: () => runTest('BSON', ({ data }) => bench.testBson(data), 21), testAvroJs: () => runTest('AVRO JS', ({ data }) => bench.testAvroJs(data), 372), testAvroAvsc: () => runTest('AVRO Avsc', ({ data }) => bench.testAvroAvsc(data), 372), testAvroAvscOptional: () => runTest('AVRO Avsc (optional)', ({ data }) => bench.testAvroAvscOptional(data), 372), - testProtoJs: () => runTest('PROTOBUF JS', ({ data }) => bench.testProtoJs(data), 153), testProtoPbf: () => runTest('PROTOBUF Pbf', ({ data }) => bench.testProtoPbf(data), 372), testProtoGoogle: () => runTest('PROTOBUF Google', ({ data }) => bench.testProtoGoogle(data), 98), diff --git a/src/plot.py b/src/plot.py index b9eba8d..57f6cb4 100644 --- a/src/plot.py +++ b/src/plot.py @@ -36,6 +36,7 @@ def main(): ALLOWED_LABELS = [ "JSON", "JSBIN", + "V8 Serialize", "AVRO Avsc", "BSER", "BSON", diff --git a/src/run-tests.sh b/src/run-tests.sh index 21d18ce..1c2d877 100644 --- a/src/run-tests.sh +++ b/src/run-tests.sh @@ -2,6 +2,8 @@ npm start 'testJson' +npm start 'testV8Serialize' + npm start 'testBson' npm start 'testAvroJs'