Skip to content

Commit 4d990f6

Browse files
committed
Merge branch 'master' into next
2 parents 14f01d3 + 1db7212 commit 4d990f6

File tree

11 files changed

+459
-31
lines changed

11 files changed

+459
-31
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ version: 2
22
updates:
33
- package-ecosystem: github-actions
44
directory: '/'
5+
ignore:
6+
- dependency-name: "actions/*"
7+
update-types:
8+
["version-update:semver-minor", "version-update:semver-patch"]
59
schedule:
610
interval: daily
711
open-pull-requests-limit: 10

.github/workflows/benchmark.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Benchmark
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
7+
jobs:
8+
benchmark:
9+
if: ${{ github.event.label.name == 'benchmark' }}
10+
runs-on: ubuntu-latest
11+
outputs:
12+
PR-BENCH-12: ${{ steps.benchmark-pr.outputs.BENCH_RESULT12 }}
13+
PR-BENCH-14: ${{ steps.benchmark-pr.outputs.BENCH_RESULT14 }}
14+
PR-BENCH-16: ${{ steps.benchmark-pr.outputs.BENCH_RESULT16 }}
15+
MAIN-BENCH-12: ${{ steps.benchmark-main.outputs.BENCH_RESULT12 }}
16+
MAIN-BENCH-14: ${{ steps.benchmark-main.outputs.BENCH_RESULT14 }}
17+
MAIN-BENCH-16: ${{ steps.benchmark-main.outputs.BENCH_RESULT16 }}
18+
strategy:
19+
matrix:
20+
node-version: [12, 14, 16]
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
ref: ${{github.event.pull_request.head.ref}}
25+
repository: ${{github.event.pull_request.head.repo.full_name}}
26+
27+
- uses: actions/setup-node@v2
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
31+
- name: Install
32+
run: |
33+
npm install --ignore-scripts
34+
35+
- name: Run benchmark
36+
id: benchmark-pr
37+
run: |
38+
npm run --silent benchmark > ./bench-result
39+
content=$(cat ./bench-result)
40+
content="${content//'%'/'%25'}"
41+
content="${content//$'\n'/'%0A'}"
42+
content="${content//$'\r'/'%0D'}"
43+
echo "::set-output name=BENCH_RESULT${{matrix.node-version}}::$content"
44+
45+
# main benchmark
46+
- uses: actions/checkout@v2
47+
with:
48+
ref: 'master'
49+
50+
- name: Install
51+
run: |
52+
npm install --ignore-scripts
53+
54+
- name: Run benchmark
55+
id: benchmark-master
56+
run: |
57+
npm run --silent benchmark > ./bench-result
58+
content=$(cat ./bench-result)
59+
content="${content//'%'/'%25'}"
60+
content="${content//$'\n'/'%0A'}"
61+
content="${content//$'\r'/'%0D'}"
62+
echo "::set-output name=BENCH_RESULT${{matrix.node-version}}::$content"
63+
64+
output-benchmark:
65+
needs: [benchmark]
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Comment PR
69+
uses: thollander/actions-comment-pull-request@v1
70+
with:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
message: |
73+
**Node**: 12
74+
**PR**:
75+
```
76+
${{ needs.benchmark.outputs.PR-BENCH-12 }}
77+
```
78+
**MAIN**:
79+
```
80+
${{ needs.benchmark.outputs.MAIN-BENCH-12 }}
81+
```
82+
83+
---
84+
85+
**Node**: 14
86+
**PR**:
87+
```
88+
${{ needs.benchmark.outputs.PR-BENCH-14 }}
89+
```
90+
**MAIN**:
91+
```
92+
${{ needs.benchmark.outputs.MAIN-BENCH-14 }}
93+
```
94+
95+
---
96+
97+
**Node**: 16
98+
**PR**:
99+
```
100+
${{ needs.benchmark.outputs.PR-BENCH-16 }}
101+
```
102+
**MAIN**:
103+
```
104+
${{ needs.benchmark.outputs.MAIN-BENCH-16 }}
105+
```
106+
107+
- uses: actions-ecosystem/action-remove-labels@v1
108+
with:
109+
labels: |
110+
benchmark
111+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
os: [macos-latest, ubuntu-latest, windows-latest]
2020

2121
steps:
22-
- uses: actions/checkout@v2.3.4
22+
- uses: actions/checkout@v2
2323

2424
- name: Use Node.js
25-
uses: actions/setup-node@v2.4.0
25+
uses: actions/setup-node@v2
2626
with:
2727
node-version: ${{ matrix.node-version }}
2828

@@ -37,7 +37,11 @@ jobs:
3737
automerge:
3838
needs: test
3939
runs-on: ubuntu-latest
40+
permissions:
41+
pull-requests: write
42+
contents: write
4043
steps:
41-
- uses: fastify/github-action-merge-dependabot@v2.4.0
44+
- uses: fastify/github-action-merge-dependabot@v3
4245
with:
4346
github-token: ${{ secrets.GITHUB_TOKEN }}
47+
target: minor

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@ fast-json-stringify requires a [JSON Schema Draft 7](https://json-schema.org/spe
1919
##### Benchmarks
2020

2121
- Machine: `EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD`.
22-
- Node.js `v12.16.2`
22+
- Node.js `v16.9.1`
2323

2424
```
25-
FJS creation x 59,805 ops/sec ±0.23% (91 runs sampled)
25+
FJS creation x 6,040 ops/sec ±1.17% (91 runs sampled)
2626
27-
JSON.stringify array x 5,330 ops/sec ±0.54% (97 runs sampled)
28-
fast-json-stringify array x 6,995 ops/sec ±0.24% (94 runs sampled)
27+
JSON.stringify array x 5,519 ops/sec ±0.08% (99 runs sampled)
28+
fast-json-stringify array x 7,143 ops/sec ±0.14% (97 runs sampled)
2929
30-
JSON.stringify long string x 15,108 ops/sec ±0.13% (100 runs sampled)
31-
fast-json-stringify long string x 15,089 ops/sec ±0.15% (98 runs sampled)
30+
JSON.stringify long string x 16,438 ops/sec ±0.32% (98 runs sampled)
31+
fast-json-stringify long string x 16,457 ops/sec ±0.09% (97 runs sampled)
3232
33-
JSON.stringify short string x 13,214,696 ops/sec ±0.19% (97 runs sampled)
34-
fast-json-stringify short string x 33,378,500 ops/sec ±0.27% (95 runs sampled)
33+
JSON.stringify short string x 12,061,258 ops/sec ±0.32% (97 runs sampled)
34+
fast-json-stringify short string x 35,531,071 ops/sec ±0.17% (94 runs sampled)
3535
36-
JSON.stringify obj x 3,172,653 ops/sec ±0.15% (98 runs sampled)
37-
fast-json-stringify obj x 13,537,123 ops/sec ±0.19% (95 runs sampled)
36+
JSON.stringify obj x 3,079,746 ops/sec ±0.09% (95 runs sampled)
37+
fast-json-stringify obj x 7,721,569 ops/sec ±0.12% (98 runs sampled)
38+
39+
JSON stringify date x 1,149,786 ops/sec ±0.10% (99 runs sampled)
40+
fast-json-stringify date format x 1,674,498 ops/sec ±0.12% (99 runs sampled)
3841
```
3942

4043
#### Table of contents:

bench.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,38 @@ const arraySchemaAJVJTD = {
6969
elements: schemaAJVJTD
7070
}
7171

72+
const dateFormatSchema = {
73+
description: 'Date of birth',
74+
type: 'string',
75+
format: 'date'
76+
}
77+
78+
const dateFormatSchemaCJS = {
79+
description: 'Date of birth',
80+
type: 'string',
81+
format: 'date'
82+
}
83+
7284
const obj = {
7385
firstName: 'Matteo',
7486
lastName: 'Collina',
7587
age: 32
7688
}
7789

90+
const date = new Date()
91+
7892
const multiArray = []
7993

8094
const CJS = require('compile-json-stringify')
8195
const CJSStringify = CJS(schemaCJS)
8296
const CJSStringifyArray = CJS(arraySchemaCJS)
97+
const CJSStringifyDate = CJS(dateFormatSchemaCJS)
8398
const CJSStringifyString = CJS({ type: 'string' })
8499

85100
const FJS = require('.')
86101
const stringify = FJS(schema)
87102
const stringifyArray = FJS(arraySchema)
103+
const stringifyDate = FJS(dateFormatSchema)
88104
const stringifyString = FJS({ type: 'string' })
89105
let str = ''
90106

@@ -182,6 +198,18 @@ suite.add('AJV Serialize obj', function () {
182198
ajvSerialize(obj)
183199
})
184200

201+
suite.add('JSON stringify date', function () {
202+
JSON.stringify(date)
203+
})
204+
205+
suite.add('fast-json-stringify date format', function () {
206+
stringifyDate(date)
207+
})
208+
209+
suite.add('compile-json-stringify date format', function () {
210+
CJSStringifyDate(date)
211+
})
212+
185213
suite.on('cycle', cycle)
186214

187215
suite.run()

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ declare namespace build {
6464

6565
export interface StringSchema extends BaseSchema {
6666
type: "string";
67+
format?: string;
6768
}
6869

6970
export interface IntegerSchema extends BaseSchema {

0 commit comments

Comments
 (0)