Repository navigation
Expand file tree
/
Copy pathBenchmarkSerializationFinal.java
More file actions
62 lines (52 loc) · 1.77 KB
/
Copy pathBenchmarkSerializationFinal.java
File metadata and controls
62 lines (52 loc) · 1.77 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
52
53
54
55
56
57
58
59
60
61
62
package benchmarks;
import java.util.*;
import org.openjdk.jmh.annotations.*;
import com.chronoxor.proto.*;
import com.chronoxor.proto.fbe.*;
@State(Scope.Benchmark)
public class BenchmarkSerializationFinal
{
private Account _account;
private final AccountFinalModel _writer;
private final AccountFinalModel _reader;
public BenchmarkSerializationFinal()
{
// Create a new account with some orders
_account = new Account(1, "Test", State.good, new Balance("USD", 1000.0), new Balance("EUR", 100.0), new ArrayList<Order>());
_account.orders.add(new Order(1, "EURUSD", OrderSide.buy, OrderType.market, 1.23456, 1000.0));
_account.orders.add(new Order(2, "EURUSD", OrderSide.sell, OrderType.limit, 1.0, 100.0));
_account.orders.add(new Order(3, "EURUSD", OrderSide.buy, OrderType.stop, 1.5, 10.0));
// Serialize the account to the FBE stream
_writer = new AccountFinalModel();
_writer.serialize(_account);
assert _writer.verify();
// Deserialize the account from the FBE stream
_reader = new AccountFinalModel();
_reader.attach(_writer.getBuffer());
assert _reader.verify();
_reader.deserialize(_account);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void verify()
{
// Verify the account
_writer.verify();
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void serialize()
{
// Reset FBE stream
_writer.reset();
// Serialize the account to the FBE stream
_writer.serialize(_account);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void deserialize()
{
// Deserialize the account from the FBE stream
_reader.deserialize(_account);
}
}