Repository navigation
Expand file tree
/
Copy pathbenchmark_serialization.js
More file actions
51 lines (39 loc) · 1.62 KB
/
Copy pathbenchmark_serialization.js
File metadata and controls
51 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const benchmark = require('benchmark')
const fbe = require('../proto/fbe')
const proto = require('../proto/proto')
const suite = new benchmark.Suite('Serialization')
suite.on('start', function () {
// Create a new account with some orders
this.account = new proto.Account(1, 'Test', proto.State.good, new proto.Balance('USD', 1000.0), new proto.Balance('EUR', 100.0))
this.account.orders.push(new proto.Order(1, 'EURUSD', proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0))
this.account.orders.push(new proto.Order(2, 'EURUSD', proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0))
this.account.orders.push(new proto.Order(3, 'EURUSD', proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0))
// Serialize the account to the FBE stream
this.writer = new proto.AccountModel(new fbe.WriteBuffer())
this.writer.serialize(this.account)
console.assert(this.writer.verify())
// Deserialize the account from the FBE stream
this.reader = new proto.AccountModel(new fbe.ReadBuffer())
this.reader.attachBuffer(this.writer.buffer)
console.assert(this.reader.verify())
this.reader.deserialize(this.account)
})
suite.on('cycle', function (event) {
console.log(String(event.target))
})
suite.add('Serialize', function () {
// Reset FBE stream
suite.writer.reset()
// Serialize the account to the FBE stream
suite.writer.serialize(suite.account)
})
suite.add('Deserialize', function () {
// Deserialize the account from the FBE stream
suite.reader.deserialize(suite.account)
})
suite.add('Verify', function () {
// Verify the account
suite.writer.verify()
})
suite.run({ async: true })