File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 run : bun run demo:decoding
2121 - name : Memory usage with intermediate string
2222 run : bun run demo:gc-strings
23+ - name : Compare await new Response(buffer).json() and JSON.parse(buffer.toString())
24+ run : bun run demo:against-response
Original file line number Diff line number Diff line change 1+ var payload1 = '{"key":"value", "key2": 123123}' ;
2+ console . info ( "Payload to be tested: " , payload1 )
3+ var buffer1 = Buffer . from ( payload1 )
4+ console . time ( "JSON.parse" )
5+ for ( var i = 0 ; i < 1_000_000 ; i ++ ) {
6+ JSON . parse ( buffer1 . toString ( ) ) ;
7+ }
8+ console . timeEnd ( "JSON.parse" )
9+ console . time ( "await Response.json()" )
10+ for ( var i = 0 ; i < 1_000_000 ; i ++ ) {
11+ await new Response ( buffer1 ) . json ( )
12+ }
13+ console . timeEnd ( "await Response.json()" )
14+
15+
16+ var payload2 = JSON . stringify (
17+ new Array ( 100 ) . fill ( { "key" :"value" , "key2" : 123123 } )
18+ ) ;
19+ console . info ( "Payload - an array of " + payload1 , "; Length in js characters:" , payload2 . length )
20+ var buffer2 = Buffer . from ( payload2 )
21+ console . time ( "JSON.parse" )
22+ for ( var i = 0 ; i < 1_000_00 ; i ++ ) {
23+ JSON . parse ( buffer2 . toString ( ) ) ;
24+ }
25+ console . timeEnd ( "JSON.parse" )
26+ console . time ( "await Response.json()" )
27+ for ( var i = 0 ; i < 1_000_00 ; i ++ ) {
28+ await new Response ( buffer2 ) . json ( )
29+ }
30+ console . timeEnd ( "await Response.json()" )
Original file line number Diff line number Diff line change 1010 "demo:decoding" : " node demo/decoding.mjs" ,
1111 "demo:json" : " node demo/json-parse.mjs" ,
1212 "demo:gc-strings" : " node --expose-gc demo/gc-strings.mjs && node --max-old-space-size=25 --expose-gc demo/gc-strings.mjs" ,
13- "demo:all" : " bun run demo:errors && bun run demo:decoding && bun run demo:json"
13+ "demo:against-response" : " node demo/against-ResponseAPI.mjs && deno demo/against-ResponseAPI.mjs && bun demo/against-ResponseAPI.mjs" ,
14+ "demo:all" : " bun run demo:errors && bun run demo:decoding && bun run demo:json && bun run demo:against-response"
1415 },
1516 "homepage" : " https://github.com/Guthib-of-Dan/proposal-json-parse-binary#readme" ,
1617 "repository" : {
You can’t perform that action at this time.
0 commit comments