Skip to content

Commit

Permalink
Add compiled benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Karang committed May 19, 2020
1 parent d390ba0 commit ac52f1a
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 18 deletions.
43 changes: 41 additions & 2 deletions benchmark/benchmark_all_types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

it('reads', function () {
Expand Down Expand Up @@ -43,3 +42,43 @@ it('writes', function () {
})
.run({ 'async': false })
})

it('reads (compiled)', function () {
this.timeout(1000 * 60 * 10)
const readSuite = new Benchmark.Suite()
readSuite.add('read (compiled)', function () {
testData.forEach(tests => {
tests.data.forEach(test => {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.parsePacketBuffer(subType.type, value.buffer)
})
})
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})

it('writes (compiled)', function () {
this.timeout(1000 * 60 * 10)
const writeSuite = new Benchmark.Suite()
writeSuite.add('write (compiled)', function () {
testData.forEach(tests => {
tests.data.forEach(test => {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.createPacketBuffer(subType.type, value.value)
})
})
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
37 changes: 35 additions & 2 deletions benchmark/benchmark_by_kind.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

testData.forEach(tests => {
Expand Down Expand Up @@ -41,5 +40,39 @@ testData.forEach(tests => {
})
.run({ 'async': false })
})

it('reads (compiled)', function () {
const readSuite = new Benchmark.Suite()
readSuite.add('read (compiled)', function () {
tests.data.forEach(test => {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.parsePacketBuffer(subType.type, value.buffer)
})
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})

it('writes (compiled)', function () {
const writeSuite = new Benchmark.Suite()
writeSuite.add('write (compiled)', function () {
tests.data.forEach(test => {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.createPacketBuffer(subType.type, value.value)
})
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
})
})
29 changes: 27 additions & 2 deletions benchmark/benchmark_by_subtype.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

function testType (type, values) {
Expand Down Expand Up @@ -30,6 +29,32 @@ function testType (type, values) {
})
.run({ 'async': false })
})

it('reads (compiled)', function () {
const readSuite = new Benchmark.Suite()
readSuite.add('read (compiled)', function () {
values.forEach((value) => {
compiledProto.parsePacketBuffer(type, value.buffer)
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})

it('writes (compiled)', function () {
const writeSuite = new Benchmark.Suite()
writeSuite.add('write (compiled)', function () {
values.forEach((value) => {
compiledProto.createPacketBuffer(type, value.value)
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
}

testData.forEach(tests => {
Expand Down
24 changes: 22 additions & 2 deletions benchmark/benchmark_by_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

function testValue (type, value, buffer) {
Expand All @@ -25,6 +24,27 @@ function testValue (type, value, buffer) {
})
.run({ 'async': false })
})

it('writes (compiled)', function () {
const suite = new Benchmark.Suite()
suite.add('writes (compiled)', function () {
compiledProto.createPacketBuffer(type, value)
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
it('reads (compiled)', function () {
const suite = new Benchmark.Suite()
suite.add('read (compiled)', function () {
compiledProto.parsePacketBuffer(type, buffer)
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
}

function testType (type, values) {
Expand Down
33 changes: 31 additions & 2 deletions benchmark/benchmark_by_type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

testData.forEach(tests => {
Expand Down Expand Up @@ -39,6 +38,36 @@ testData.forEach(tests => {
})
.run({ 'async': false })
})

it('reads (compiled)', function () {
const readSuite = new Benchmark.Suite()
readSuite.add('read (compiled)', function () {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.parsePacketBuffer(subType.type, value.buffer)
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})

it('writes (compiled)', function () {
const writeSuite = new Benchmark.Suite()
writeSuite.add('write (compiled)', function () {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.createPacketBuffer(subType.type, value.value)
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
})
})
})
Expand Down
24 changes: 22 additions & 2 deletions benchmark/benchmark_unified.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */

const testData = require('../test/dataTypes/prepareTests').testData
const proto = require('../test/dataTypes/prepareTests').proto
const { testData, proto, compiledProto } = require('../test/dataTypes/prepareTests')
const Benchmark = require('benchmark')

it('read/write', function () {
Expand All @@ -24,3 +23,24 @@ it('read/write', function () {
})
.run({ 'async': false })
})

it('read/write (compiled)', function () {
this.timeout(1000 * 60 * 10)
const suite = new Benchmark.Suite()
suite.add('read/write (compiled)', function () {
testData.forEach(tests => {
tests.data.forEach(test => {
test.subtypes.forEach(subType => {
subType.values.forEach((value) => {
compiledProto.parsePacketBuffer(subType.type, value.buffer)
compiledProto.createPacketBuffer(subType.type, value.value)
})
})
})
})
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run({ 'async': false })
})
4 changes: 1 addition & 3 deletions src/datatypes/compiler-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ module.exports = {
}
}
if (bits !== 0) {
code += 'buffer[offset++] = ' + toWrite + ' << ' + (8 - bits) + '\n'
bits = 0
toWrite = ''
code += 'buffer[offset++] = (' + toWrite + ') << ' + (8 - bits) + '\n'
}
code += 'return offset'
return compiler.wrapCode(code)
Expand Down
8 changes: 5 additions & 3 deletions test/dataTypes/prepareTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ testData.forEach(tests => {
})
})

module.exports.compiledProto = compiler.compileProtoDefSync()
module.exports.testData = testData
module.exports.proto = proto
module.exports = {
testData,
proto,
compiledProto: compiler.compileProtoDefSync()
}

0 comments on commit ac52f1a

Please sign in to comment.