asStringSmall seem slower than JSON.stringify
Closed this issue · 0 comments
cesco69 commented
asStringSmall seem slower than JSON.stringify
it seems better to use JSON stringify instead of asStringSmall
In detail:
// Test cases ...
const STR_1 = 'A'
const STR_10 = STR_1.repeat(10) // 10 chars
const STR_20 = STR_1.repeat(20) // 20 chars
const STR_30 = STR_1.repeat(30) // 30 chars
const STR_40 = STR_1.repeat(40) // 40 chars
asStringSmall(STR_1) 221,230 ops/s
JSON.stringify(STR_1) 639,110 ops/s
asStringSmall(STR_10) 73,130 ops/s
JSON.stringify(STR_10) 598,020 ops/s
asStringSmall(STR_20) 38,900 ops/s
JSON.stringify(STR_20) 596,480 ops/s
asStringSmall(STR_30) 29,960 ops/s
JSON.stringify(STR_30) 413,430 ops/s
asStringSmall(STR_40) 21,840 ops/s
JSON.stringify(STR_40) 460,970 ops/s
JSON.stringify win in all cases.