Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Node's built-in binary V8 serialize/deserialize #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ export function testJson(testData: any): Promise<BenchmarkResult> {
export function testJsonUnmapped(testData: any): Promise<BenchmarkResult> {
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<BenchmarkResult> {
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',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def main():
ALLOWED_LABELS = [
"JSON",
"JSBIN",
"V8 Serialize",
"AVRO Avsc",
"BSER",
"BSON",
Expand Down
2 changes: 2 additions & 0 deletions src/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

npm start 'testJson'

npm start 'testV8Serialize'

npm start 'testBson'

npm start 'testAvroJs'
Expand Down