json-parser-benchmark

module
v0.0.0-...-e530ac3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2022 License: GPL-3.0

README

测试 各种编程语言的json序列化反序列化能力

当前仅支持了 Go 语言和 Rust 语言的代码。

使用 Twitter.json, 这也是 simdjson 和字节跳动sonic测试的场景之一。

Go

BenchmarkSonic_Marshal
BenchmarkSonic_Marshal-2        	   76606	     14820 ns/op	   10732 B/op	       4 allocs/op
BenchmarkSonic_Unmarshal
BenchmarkSonic_Unmarshal-2      	   16495	     71858 ns/op	   18143 B/op	       3 allocs/op
BenchmarkEasyJson_Marshal
BenchmarkEasyJson_Marshal-2     	    7506	    153739 ns/op	   20190 B/op	      63 allocs/op
BenchmarkEasyJson_Unmarshal
BenchmarkEasyJson_Unmarshal-2   	    3248	    368230 ns/op	    4744 B/op	     128 allocs/op
BenchmarkJsoniter_Marshal
BenchmarkJsoniter_Marshal-2     	   37672	     32388 ns/op	   20211 B/op	      64 allocs/op
BenchmarkJsoniter_Unmarshal
BenchmarkJsoniter_Unmarshal-2   	    8688	    166978 ns/op	   26194 B/op	     444 allocs/op

看一看到Sonic的序列化和反序列化d都非常优秀。这序列化反序列化twitter.json时,序列化平均需要16微秒(μs), 反序列化需要82微秒(μs)。

相比较而言,大家常用Jsoniter、EasyJson耗时是它的两到三倍,所以如果你的程序不得不使用JSON的话,如果想提升性能,可以考虑使用sonic替换。

Rust

Rust常用的Json序列化反序列化框架是serde-json

虽然一种常见的方式是解析成成JsonValue的方式,但是我们还是用和Go语言相匹配的方式,解析成struct。

     Running benches/bench.rs (target/release/deps/bench-72246fe0c0b1d2fa)
twitter-serde/twitter-serde-marshal
                        time:   [9.0386 µs 9.0536 µs 9.0707 µs]
                        thrpt:  [1.6595 GiB/s 1.6626 GiB/s 1.6654 GiB/s]
Found 41 outliers among 500 measurements (8.20%)
  3 (0.60%) low mild
  11 (2.20%) high mild
  27 (5.40%) high severe
twitter-serde/twitter-serde-unmarshal
                        time:   [35.772 µs 35.861 µs 35.966 µs]
                        thrpt:  [428.58 MiB/s 429.83 MiB/s 430.90 MiB/s]
Found 31 outliers among 500 measurements (6.20%)
  9 (1.80%) high mild
  22 (4.40%) high severe

可以看到serde序列化只需要9微秒(μs), 反序列化只需要36微秒(μs)。

即使像sonic这样高度优化的Go序列化库,也比不上rust的序列化库,rust语言性能优势这么明显么?

C++

  • simdjson
  • ffjson

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL