fast-json-stringify
fast-json-stringify copied to clipboard
perf: monomorfic variables
Monomorphic: If a property always gets the same class shape.
It'a a good performance improvments on Array and Object, but not on primitive types
Raw benchmark
Checking out "remotes/origin/monomorfic-variables"
Execute "npm run bench"
> [email protected] bench
> node ./benchmark/bench.js
short string............................................. x 22,911,344 ops/sec ±4.53% (162 runs sampled)
unsafe short string...................................... x 73,650,931 ops/sec ±5.05% (144 runs sampled)
short string with double quote........................... x 9,470,207 ops/sec ±2.16% (150 runs sampled)
long string without double quotes........................ x 36,234 ops/sec ±1.78% (160 runs sampled)
unsafe long string without double quotes................. x 75,229,690 ops/sec ±4.33% (150 runs sampled)
long string.............................................. x 32,157 ops/sec ±2.33% (169 runs sampled)
unsafe long string....................................... x 66,281,516 ops/sec ±4.12% (156 runs sampled)
number................................................... x 75,618,262 ops/sec ±5.33% (140 runs sampled)
integer.................................................. x 57,630,179 ops/sec ±3.43% (140 runs sampled)
formatted date-time...................................... x 690,716 ops/sec ±2.03% (154 runs sampled)
formatted date........................................... x 630,836 ops/sec ±2.90% (152 runs sampled)
formatted time........................................... x 600,154 ops/sec ±2.42% (153 runs sampled)
short array of numbers................................... x 40,187 ops/sec ±1.25% (159 runs sampled)
short array of integers.................................. x 42,814 ops/sec ±2.64% (164 runs sampled)
short array of short strings............................. x 14,476 ops/sec ±4.01% (174 runs sampled)
short array of long strings.............................. x 13,235 ops/sec ±2.99% (161 runs sampled)
short array of objects with properties of different types x 5,675 ops/sec ±2.49% (158 runs sampled)
object with number property.............................. x 91,517,822 ops/sec ±6.67% (152 runs sampled)
object with integer property............................. x 84,343,207 ops/sec ±5.90% (178 runs sampled)
object with short string property........................ x 25,917,292 ops/sec ±1.44% (189 runs sampled)
object with long string property......................... x 47,750 ops/sec ±0.87% (192 runs sampled)
object with properties of different types................ x 1,638,590 ops/sec ±2.34% (183 runs sampled)
simple object............................................ x 9,364,675 ops/sec ±1.50% (185 runs sampled)
simple object with required fields....................... x 9,364,717 ops/sec ±1.52% (184 runs sampled)
object with const string property........................ x 119,169,683 ops/sec ±4.21% (171 runs sampled)
object with const number property........................ x 118,606,339 ops/sec ±4.47% (170 runs sampled)
object with const bool property.......................... x 111,100,119 ops/sec ±4.81% (166 runs sampled)
object with const object property........................ x 118,926,898 ops/sec ±4.21% (172 runs sampled)
object with const null property.......................... x 107,150,234 ops/sec ±5.15% (168 runs sampled)
Checking out "master"
Execute "npm run bench"
> [email protected] bench
> node ./benchmark/bench.js
short string............................................. x 24,388,745 ops/sec ±2.12% (183 runs sampled)
unsafe short string...................................... x 84,244,363 ops/sec ±6.69% (148 runs sampled)
short string with double quote........................... x 9,644,133 ops/sec ±3.14% (155 runs sampled)
long string without double quotes........................ x 41,509 ops/sec ±4.43% (170 runs sampled)
unsafe long string without double quotes................. x 105,877,016 ops/sec ±5.25% (162 runs sampled)
long string.............................................. x 48,014 ops/sec ±1.04% (194 runs sampled)
unsafe long string....................................... x 117,193,911 ops/sec ±5.03% (169 runs sampled)
number................................................... x 106,082,837 ops/sec ±5.85% (159 runs sampled)
integer.................................................. x 100,649,516 ops/sec ±4.47% (172 runs sampled)
formatted date-time...................................... x 1,249,090 ops/sec ±1.22% (191 runs sampled)
formatted date........................................... x 669,947 ops/sec ±4.04% (152 runs sampled)
formatted time........................................... x 587,616 ops/sec ±0.73% (188 runs sampled)
short array of numbers................................... x 38,787 ops/sec ±1.61% (155 runs sampled)
short array of integers.................................. x 39,458 ops/sec ±2.21% (154 runs sampled)
short array of short strings............................. x 12,415 ops/sec ±2.22% (156 runs sampled)
short array of long strings.............................. x 12,322 ops/sec ±1.40% (155 runs sampled)
short array of objects with properties of different types x 5,810 ops/sec ±1.93% (154 runs sampled)
object with number property.............................. x 66,543,631 ops/sec ±5.88% (145 runs sampled)
object with integer property............................. x 58,760,516 ops/sec ±4.69% (142 runs sampled)
object with short string property........................ x 14,679,314 ops/sec ±2.50% (148 runs sampled)
object with long string property......................... x 39,914 ops/sec ±3.19% (183 runs sampled)
object with properties of different types................ x 1,576,563 ops/sec ±2.94% (162 runs sampled)
simple object............................................ x 8,133,777 ops/sec ±2.20% (180 runs sampled)
simple object with required fields....................... x 8,273,155 ops/sec ±2.32% (176 runs sampled)
object with const string property........................ x 109,001,760 ops/sec ±5.33% (164 runs sampled)
object with const number property........................ x 108,746,170 ops/sec ±5.35% (166 runs sampled)
object with const bool property.......................... x 103,566,758 ops/sec ±6.00% (159 runs sampled)
object with const object property........................ x 112,981,394 ops/sec ±4.63% (167 runs sampled)
object with const null property.......................... x 115,251,679 ops/sec ±4.77% (168 runs sampled)
short string..............................................-6.06%
unsafe short string......................................-12.57%
short string with double quote.............................-1.8%
long string without double quotes........................-12.71%
unsafe long string without double quotes.................-28.95%
long string..............................................-33.03%
unsafe long string.......................................-43.44%
number...................................................-28.72%
integer..................................................-42.74%
formatted date-time.......................................-44.7%
formatted date............................................-5.84%
formatted time............................................+2.13%
short array of numbers....................................+3.61%
short array of integers...................................+8.51%
short array of short strings..............................+16.6%
short array of long strings...............................+7.41%
short array of objects with properties of different types.-2.32%
object with number property..............................+37.53%
object with integer property.............................+43.54%
object with short string property........................+76.56%
object with long string property.........................+19.63%
object with properties of different types.................+3.93%
simple object............................................+15.13%
simple object with required fields.......................+13.19%
object with const string property.........................+9.33%
object with const number property.........................+9.07%
object with const bool property...........................+7.27%
object with const object property.........................+5.26%
object with const null property...........................-7.03%
Back to master 2b37f1d