Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flattened strings optimization #32

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions benchmark-flattened.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

> [email protected] benchmark /Users/luca.gesmundo/me/slow-json-stringify
> cd benchmark && sh run.sh


# Benchmarks

Benchmarks performed on:
- native **JSON.stringify**
- **fast-json-stringify**
- **slow-json-stringify**


## small-object

```bash
native x 3,256,671 ops/sec ±0.64% (91 runs sampled)
fast-json-stringify x 46,090,717 ops/sec ±0.22% (95 runs sampled)
slow-json-stringify x 46,056,000 ops/sec ±0.65% (92 runs sampled)

# fast-json-stringify,slow-json-stringify is +0.08% faster

```

## small-array

```bash
native x 272,422 ops/sec ±0.24% (96 runs sampled)
fast-json-stringify x 345,767 ops/sec ±0.44% (97 runs sampled)
slow-json-stringify x 959,721 ops/sec ±0.53% (89 runs sampled)

# slow-json-stringify is +177.56% faster

```

## nested-props-short-text

```bash
native x 693,847 ops/sec ±0.43% (93 runs sampled)
fast-json-stringify x 3,258,606 ops/sec ±0.25% (94 runs sampled)
slow-json-stringify x 10,205,115 ops/sec ±0.96% (91 runs sampled)

# slow-json-stringify is +213.17% faster

```

## much-props-short-text

```bash
native x 575,735 ops/sec ±1.03% (91 runs sampled)
fast-json-stringify x 724,984 ops/sec ±1.31% (89 runs sampled)
slow-json-stringify x 2,137,405 ops/sec ±0.75% (89 runs sampled)

# slow-json-stringify is +194.82% faster

```

## much-props-big-text

```bash
native x 13,479 ops/sec ±4.24% (83 runs sampled)
fast-json-stringify x 13,100 ops/sec ±3.16% (83 runs sampled)
slow-json-stringify x 2,260,389 ops/sec ±1.37% (92 runs sampled)

# slow-json-stringify is +16670.95% faster

```

## big-text

```bash
native x 192,588 ops/sec ±0.50% (89 runs sampled)
fast-json-stringify x 200,919 ops/sec ±0.69% (90 runs sampled)
slow-json-stringify x 44,768,200 ops/sec ±1.21% (91 runs sampled)

# slow-json-stringify is +22181.83% faster

```

## big-array-short-text

```bash
native x 3,717 ops/sec ±0.49% (89 runs sampled)
slow-json-stringify x 8,777 ops/sec ±1.55% (89 runs sampled)

# slow-json-stringify is +136.13% faster

```

## big-array-long-text

```bash
native x 76.69 ops/sec ±0.72% (74 runs sampled)
slow-json-stringify x 8,595 ops/sec ±0.58% (89 runs sampled)

# slow-json-stringify is +11209.21% faster

```

## big-array-long-number

```bash
native x 871 ops/sec ±2.96% (85 runs sampled)
slow-json-stringify x 2,643 ops/sec ±1.39% (88 runs sampled)

# slow-json-stringify is +203.68% faster

```

## undefined properties

```bash
native x 1,541,588 ops/sec ±6.02% (77 runs sampled)
fast-json-stringify x 8,287,034 ops/sec ±1.53% (91 runs sampled)
slow-json-stringify x 14,304,614 ops/sec ±1.23% (84 runs sampled)

# slow-json-stringify is +72.61% faster

```

120 changes: 120 additions & 0 deletions benchmark-normal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

> [email protected] benchmark /Users/luca.gesmundo/me/slow-json-stringify
> cd benchmark && sh run.sh


# Benchmarks

Benchmarks performed on:
- native **JSON.stringify**
- **fast-json-stringify**
- **slow-json-stringify**


## small-object

```bash
native x 3,730,490 ops/sec ±2.84% (91 runs sampled)
fast-json-stringify x 55,217,937 ops/sec ±0.12% (95 runs sampled)
slow-json-stringify x 56,829,533 ops/sec ±0.59% (94 runs sampled)

# slow-json-stringify is +2.92% faster

```

## small-array

```bash
native x 339,112 ops/sec ±0.53% (88 runs sampled)
fast-json-stringify x 425,930 ops/sec ±0.53% (97 runs sampled)
slow-json-stringify x 1,192,221 ops/sec ±1.09% (92 runs sampled)

# slow-json-stringify is +179.91% faster

```

## nested-props-short-text

```bash
native x 838,737 ops/sec ±0.66% (91 runs sampled)
fast-json-stringify x 3,577,531 ops/sec ±0.55% (93 runs sampled)
slow-json-stringify x 11,501,223 ops/sec ±0.36% (92 runs sampled)

# slow-json-stringify is +221.48% faster

```

## much-props-short-text

```bash
native x 745,820 ops/sec ±0.35% (93 runs sampled)
fast-json-stringify x 860,018 ops/sec ±1.13% (86 runs sampled)
slow-json-stringify x 2,348,637 ops/sec ±0.65% (84 runs sampled)

# slow-json-stringify is +173.09% faster

```

## much-props-big-text

```bash
native x 19,760 ops/sec ±0.80% (84 runs sampled)
fast-json-stringify x 18,744 ops/sec ±0.78% (93 runs sampled)
slow-json-stringify x 3,195,613 ops/sec ±0.44% (95 runs sampled)

# slow-json-stringify is +16072.13% faster

```

## big-text

```bash
native x 252,588 ops/sec ±0.52% (92 runs sampled)
fast-json-stringify x 263,067 ops/sec ±0.53% (94 runs sampled)
slow-json-stringify x 57,227,748 ops/sec ±0.65% (90 runs sampled)

# slow-json-stringify is +21654.14% faster

```

## big-array-short-text

```bash
native x 4,381 ops/sec ±0.40% (96 runs sampled)
slow-json-stringify x 10,782 ops/sec ±0.37% (96 runs sampled)

# slow-json-stringify is +146.09% faster

```

## big-array-long-text

```bash
native x 95.06 ops/sec ±0.73% (80 runs sampled)
slow-json-stringify x 10,981 ops/sec ±0.37% (96 runs sampled)

# slow-json-stringify is +11458.95% faster

```

## big-array-long-number

```bash
native x 1,145 ops/sec ±0.35% (94 runs sampled)
slow-json-stringify x 3,746 ops/sec ±0.95% (93 runs sampled)

# slow-json-stringify is +227.16% faster

```

## undefined properties

```bash
native x 2,366,286 ops/sec ±0.16% (95 runs sampled)
fast-json-stringify x 7,097,273 ops/sec ±0.19% (94 runs sampled)
slow-json-stringify x 18,652,897 ops/sec ±0.38% (94 runs sampled)

# slow-json-stringify is +162.82% faster

```

123 changes: 123 additions & 0 deletions benchmark-relative-flattened.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

> [email protected] benchmark /Users/luca.gesmundo/me/slow-json-stringify
> cd benchmark && sh run.sh


# Benchmarks

Benchmarks performed on:
- native **JSON.stringify**
- **fast-json-stringify**
- **slow-json-stringify**


## small-object

```bash
native x 3,633,001 ops/sec ±2.96% (89 runs sampled)
slow-json-stringify x 52,006,413 ops/sec ±1.01% (95 runs sampled)
slow-json-stringify-flatten x 51,590,192 ops/sec ±0.77% (95 runs sampled)

# slow-json-stringify is +0.81% faster

```

## small-array

```bash
native x 316,794 ops/sec ±5.31% (84 runs sampled)
slow-json-stringify x 1,014,889 ops/sec ±1.34% (85 runs sampled)
slow-json-stringify-flatten x 1,105,377 ops/sec ±0.58% (89 runs sampled)

# slow-json-stringify-flatten is +8.92% faster

```

## nested-props-short-text

```bash
native x 824,463 ops/sec ±1.19% (89 runs sampled)
slow-json-stringify x 10,993,159 ops/sec ±0.29% (90 runs sampled)
slow-json-stringify-flatten x 11,585,080 ops/sec ±0.96% (93 runs sampled)

# slow-json-stringify-flatten is +5.38% faster

```

## much-props-short-text

```bash
native x 751,831 ops/sec ±0.80% (95 runs sampled)
slow-json-stringify x 2,455,491 ops/sec ±0.91% (89 runs sampled)
slow-json-stringify-flatten x 2,515,419 ops/sec ±0.46% (93 runs sampled)

# slow-json-stringify-flatten is +2.44% faster

```

## much-props-big-text

```bash
native x 20,618 ops/sec ±0.71% (92 runs sampled)
slow-json-stringify x 2,756,923 ops/sec ±0.51% (94 runs sampled)
slow-json-stringify-flatten x 2,824,019 ops/sec ±0.56% (90 runs sampled)

# slow-json-stringify-flatten is +2.43% faster

```

## big-text

```bash
native x 255,721 ops/sec ±0.47% (89 runs sampled)
slow-json-stringify x 56,802,176 ops/sec ±0.17% (97 runs sampled)
slow-json-stringify-flatten x 56,594,977 ops/sec ±0.43% (94 runs sampled)

# slow-json-stringify,slow-json-stringify-flatten is +0.37% faster

```

## big-array-short-text

```bash
native x 4,393 ops/sec ±0.81% (95 runs sampled)
slow-json-stringify x 9,518 ops/sec ±1.33% (90 runs sampled)
slow-json-stringify-flatten x 9,492 ops/sec ±0.44% (91 runs sampled)

# slow-json-stringify-flatten,slow-json-stringify is +0.27% faster

```

## big-array-long-text

```bash
native x 92.41 ops/sec ±0.97% (78 runs sampled)
slow-json-stringify x 9,519 ops/sec ±0.73% (89 runs sampled)
slow-json-stringify-flatten x 9,560 ops/sec ±0.44% (93 runs sampled)

# slow-json-stringify-flatten,slow-json-stringify is +0.43% faster

```

## big-array-long-number

```bash
native x 1,102 ops/sec ±0.67% (90 runs sampled)
slow-json-stringify x 3,089 ops/sec ±1.81% (88 runs sampled)
slow-json-stringify-flatten x 3,300 ops/sec ±1.27% (87 runs sampled)

# slow-json-stringify-flatten is +6.87% faster

```

## undefined properties

```bash
native x 2,372,475 ops/sec ±0.36% (90 runs sampled)
slow-json-stringify x 19,522,029 ops/sec ±1.03% (94 runs sampled)
slow-json-stringify-flatten x 20,519,716 ops/sec ±0.36% (94 runs sampled)

# slow-json-stringify-flatten is +5.11% faster

```

1 change: 1 addition & 0 deletions benchmark/big-array-long-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ console.log('```bash');

suite
.add('native', () => JSON.stringify(obj))
.add('slow-json-stringify-flatten', () => slowStringify(obj, true))
.add('slow-json-stringify', () => slowStringify(obj))
.on('cycle', (event) => {
res.push(Math.floor(event.target.hz));
Expand Down
1 change: 1 addition & 0 deletions benchmark/big-array-long-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ console.log('```bash');
// console.log(slowStringify(obj));
suite
.add('native', () => JSON.stringify(obj))
.add('slow-json-stringify-flatten', () => slowStringify(obj, true))
.add('slow-json-stringify', () => slowStringify(obj))
.on('cycle', (event) => {
res.push(Math.floor(event.target.hz));
Expand Down
1 change: 1 addition & 0 deletions benchmark/big-array-short-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ console.log('```bash');
// console.log(slowStringify(obj));
suite
.add('native', () => JSON.stringify(obj))
.add('slow-json-stringify-flatten', () => slowStringify(obj, true))
.add('slow-json-stringify', () => slowStringify(obj))
.on('cycle', (event) => {
res.push(Math.floor(event.target.hz));
Expand Down
2 changes: 1 addition & 1 deletion benchmark/big-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ console.log('```bash');

suite
.add('native', () => JSON.stringify(obj))
.add('fast-json-stringify', () => fastStringify(obj))
.add('slow-json-stringify-flatten', () => slowStringify(obj, true))
.add('slow-json-stringify', () => slowStringify(obj))
.on('cycle', (event) => {
res.push(Math.floor(event.target.hz));
Expand Down
Loading