Created
March 19, 2019 00:36
-
-
Save wemeetagain/7782032f5a82504bac4f95a21252863b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Benchmark = require('benchmark') | |
const ssz = require('../ssz-js/src') | |
const {serialize, deserialize, hashTreeRoot} = require('../ssz-ts/lib') | |
const suite = new Benchmark.Suite | |
const SubObj = { | |
fields: [ | |
['x', 'uint8'], | |
['y', 'uint16'], | |
['z', 'uint16'], | |
] | |
} | |
const Obj = { | |
fields: [ | |
['a', [SubObj]], | |
['b', 'bytes'] | |
] | |
} | |
function generateObj() { | |
return { | |
a: [{x: 4, y: 1000, z: 50}], | |
b: Buffer.from([1,2,3,4,5,6,7,8]) | |
} | |
} | |
const obj = generateObj() | |
const buf = serialize(obj, Obj) | |
suite | |
.add('JS serialize', () => ssz.serialize(obj, Obj)) | |
.add('JS deserialize', () => ssz.deserialize(buf, Obj)) | |
.add('JS hashTreeRoot', () => ssz.treeHash(obj, Obj)) | |
.add('TS serialize', () => serialize(obj, Obj)) | |
.add('TS deserialize', () => deserialize(buf, Obj)) | |
.add('TS hashTreeRoot', () => hashTreeRoot(obj, Obj)) | |
.on('cycle', (evt) => console.log(String(evt.target))) | |
.run({async: true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment