mockOne := [ |map|
map := Dictionary new.
32 timesRepeat: [
map
at: 1000 atRandom asWords asSymbol
put: {
2 atRandom = 1.
1e9 atRandom.
1e9 atRandom negated.
1000 atRandom asWords.
1e6 atRandom seconds humanReadablePrintString.
nil.
DateAndTime now printString.
(-1000 to: 1000) atRandom * Float pi } atRandom ].
map ].
mocks := (1 to: 1000) collect:[:i| mockOne value].
randomGenerator := SecureRandom new.
getOne := [ mocks atRandom: randomGenerator ].
one := getOne value.
fuelSerializer := FLSerializer newDefault.
dataStream := [:oject| MCDataStream streamedRepresentationOf: object].
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
aStream := WriteStream on: (ByteArray new: 100).
fuelSerializer serialize: one on: aStream.
aStream contents
].
].
"B is 65.26% SLOWER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
STON toString: one.
].
].
"B is 33.07% FASTER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
NeoJSONWriter toString: one.
].
].
"B is 89.40% FASTER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
dataStream value: one ]
b: [
one := getOne value.
STON toString: one.
].
].
"B is 88.26% SLOWER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
NeoJSONWriter toString: one. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 476.56% FASTER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 979.82% FASTER than A"
ABBench bench: [
ABBench
a: [
one := getOne value.
aStream := WriteStream on: (ByteArray new: 100).
fuelSerializer serialize: one on: aStream. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 3313.03% FASTER than A"
Created
November 28, 2022 16:47
-
-
Save sebastianconcept/6736e94bfa1d9c40b2cf3ea1a98b7d8e to your computer and use it in GitHub Desktop.
Serialize benchmarks BSON vs STON vs NeoJSON vs Fuel vs MCDataStream
Running my blocks with ABBench gives this (which conforms to my previous measurements):
ABBench bench: [
ABBench
a: [ MCDataStream streamedRepresentationOf: mappings atRandom ]
b: [ NeoJSONWriter toString: mappings atRandom ] ].
"B is 53.53% FASTER than A"
ABBench bench: [
ABBench
a: [ NeoJSONWriter toString: mappings atRandom ]
b: [ MCDataStream streamedRepresentationOf: mappings atRandom ] ].
"B is 31.35% SLOWER than A"
And I think I found the problem: you made a typo in the dataStream block:
dataStream := [:oject | MCDataStream streamedRepresentationOf: object].
it has to be:
dataStream := [:object | MCDataStream streamedRepresentationOf: object].
In the first case, the actual parameter is ignored and object is nil, hence that is serialised as just a single byte #[1], of course this is very fast ;-)
🤦🏻♂️ Oh boy... that was nasty! 😂
Great catch @svenvc
so... NeoJSONWriter will be the preferred one then! And by a lot!
[ one := getOne value. NeoJSONWriter toString: one ] bench. "'15433.940 per second'"
[ one := getOne value. dataStream value: one ] bench. "'8704.977 per second'"
And correcting previous tests:
mockOne := [ |map|
map := Dictionary new.
32 timesRepeat: [
map
at: 1000 atRandom asWords asSymbol
put: {
2 atRandom = 1.
1e9 atRandom.
1e9 atRandom negated.
1000 atRandom asWords.
1e6 atRandom seconds humanReadablePrintString.
nil.
DateAndTime now printString.
(-1000 to: 1000) atRandom * Float pi } atRandom ].
map ].
mocks := (1 to: 1000) collect:[:i| mockOne value].
randomGenerator := Random new.
getOne := [ mocks atRandom: randomGenerator ].
one := getOne value.
fuelSerializer := FLSerializer newDefault.
dataStream := [ :object | MCDataStream streamedRepresentationOf: object ].
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
aStream := WriteStream on: (ByteArray new: 100).
fuelSerializer serialize: one on: aStream.
aStream contents
].
].
"B is 71.35% SLOWER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
STON toString: one.
].
].
"B is 14.45% FASTER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
NeoJSONWriter toString: one.
].
].
"B is 63.02% FASTER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
dataStream value: one ]
b: [
one := getOne value.
STON toString: one.
].
].
"B is 5.15% SLOWER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
NeoJSONWriter toString: one. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 33.39% SLOWER than A"
ABBench bench: [
ABBench
a: [ one := getOne value.
serialized := BSON write: one. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 12.72% FASTER than A"
ABBench bench: [
ABBench
a: [
one := getOne value.
aStream := WriteStream on: (ByteArray new: 100).
fuelSerializer serialize: one on: aStream. ]
b: [
one := getOne value.
dataStream value: one.
].
].
"B is 332.32% FASTER than A"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah @svenvc I thought you were also using it.
Here it is for your reference:
https://github.com/emdonahue/ABBench
It might be something with the test itself?
I'll take samples again but not using ABBench, and use the closure
bench
method instead.Intrigued.