Skip to content

Commit

Permalink
Remove rollup.config.js and add benchmarking scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
meded7 committed Mar 27, 2024
1 parent 0fc92b7 commit f69c680
Show file tree
Hide file tree
Showing 10 changed files with 3,011 additions and 5,731 deletions.
61 changes: 61 additions & 0 deletions port/js/benchmarks/fromEntries.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { bench } from 'vitest'

import {Struct} from '../src/messgen.js';
import {Buffer} from './src-variant/messgen-old.js';
import { Buffer as BufferFormEntries} from './src-variant/messgen-fromEntries.js';

import { bench, describe } from 'vitest'

let srcStruct = new Struct({
id: 2,
fields: [
{ name: 'type_Int8', type: 'Int8' },
{ name: 'type_Uint8', type: 'Uint8' },
{ name: 'type_Int16', type: 'Int16' },
{ name: 'type_Uint16', type: 'Uint16' },
{ name: 'type_Int32', type: 'Int32' },
{ name: 'type_Uint32', type: 'Uint32' },
{ name: 'type_Int64', type: 'Int64' },
{ name: 'type_Uint64', type: 'Uint64' },
{ name: 'type_String', type: 'String' },
{ name: 'type_Double', type: 'Double' },
{ name: 'type_Char', type: 'Char' }
]
});

let srcData = {
type_Int8: 8,
type_Uint8: 8,
type_Int16: 8,
type_Uint16: 8,
type_Int32: 8,
type_Uint32: 8,
type_Int64: BigInt(8),
type_Uint64: BigInt(8),
type_String: 'This is test string',
type_Double: -Math.PI,
type_Char: 'A'
};
srcData.__SIZE__ = Buffer.calcSize(Buffer.createValueArray(srcStruct.fields, srcData));
let b = Buffer.serializeObj(srcStruct.schema.fields, srcData);



describe('Object.fromEntries vs mutation Object ', () => {

beforeEach(() => {
srcData = {
...srcData,
type_Int32: srcData.type_Int32 + 1,
};
srcData.__SIZE__ = Buffer.calcSize(Buffer.createValueArray(srcStruct.fields, srcData));
b = Buffer.serializeObj(srcStruct.schema.fields, srcData);
})
bench('Object.fromEntries', () => {
let res = new BufferFormEntries(b).deserialize(srcStruct);
})
bench('mutation Object', () => {
let res = new Buffer(b).deserialize(srcStruct);
})

})
50 changes: 50 additions & 0 deletions port/js/benchmarks/serializeObj.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {Buffer, Struct} from '../src/messgen.js';
import { bench, describe } from 'vitest'

let srcStruct = new Struct({
id: 2,
fields: [
{ name: 'type_Int8', type: 'Int8' },
{ name: 'type_Uint8', type: 'Uint8' },
{ name: 'type_Int16', type: 'Int16' },
{ name: 'type_Uint16', type: 'Uint16' },
{ name: 'type_Int32', type: 'Int32' },
{ name: 'type_Uint32', type: 'Uint32' },
{ name: 'type_Int64', type: 'Int64' },
{ name: 'type_Uint64', type: 'Uint64' },
{ name: 'type_String', type: 'String' },
{ name: 'type_Double', type: 'Double' },
{ name: 'type_Char', type: 'Char' }
]
});

let srcData = {
type_Int8: 8,
type_Uint8: 8,
type_Int16: 8,
type_Uint16: 8,
type_Int32: 8,
type_Uint32: 8,
type_Int64: BigInt(8),
type_Uint64: BigInt(8),
type_String: 'This is test string',
type_Double: -Math.PI,
type_Char: 'A'
};
srcData.__SIZE__ = Buffer.calcSize(Buffer.createValueArray(srcStruct.fields, srcData));
let b = Buffer.serializeObj(srcStruct.schema.fields, srcData);

describe('Buffer Operations', () => {
bench('calculate size', () => {
srcData.__SIZE__ = Buffer.calcSize(Buffer.createValueArray(srcStruct.fields, srcData));
}, { time: 1000 })

bench('serialize object', () => {
let b = Buffer.serializeObj(srcStruct.schema.fields, srcData);
}, { time: 1000 })

bench('deserialize object', () => {
let res = new Buffer(b).deserialize(srcStruct);
}, { time: 1000 })
})

Loading

0 comments on commit f69c680

Please sign in to comment.