ssbc / bipf

Binary json codec optimized for in-place access
MIT License
48 stars 9 forks source link

Bump up seek tag check #13

Closed Barbarrosa closed 3 years ago

Barbarrosa commented 3 years ago

I noticed that the seekKey and seekKey2 functions run operations that can be discarded if the tag type doesn't match. This PR moves those operations after the tag check.

Barbarrosa commented 3 years ago

Before

operation, ops/ms
binary.encode 1.5883100381194408
JSON.stringify 5.213764337851929
binary.decode 6.176652254478073
JSON.parse 6.476683937823834
JSON.parse(buffer) 6.253908692933083
JSON.stringify(JSON.parse()) 3.5423308537017357
binary.seek(string) 625
binary.seek2(encoded) 2500
binary.seek(buffer) 5000
binary.seekPath(encoded) 1111.111111111111
binary.seekPath(compiled) 5000
binary.compare() 666.6666666666666

After

operation, ops/ms
binary.encode 1.5910898965791567
JSON.stringify 5.170630816959669
binary.decode 6.086427267194157
JSON.parse 6.265664160401003
JSON.parse(buffer) 6.333122229259025
JSON.stringify(JSON.parse()) 3.6114120621162873
binary.seek(string) 1666.6666666666667
binary.seek2(encoded) 2500
binary.seek(buffer) 10000
binary.seekPath(encoded) 1111.111111111111
binary.seekPath(compiled) 5000
binary.compare() 1250
arj03 commented 3 years ago

wow, nice improvement!