Skip to content

Commit d4f4bd5

Browse files
committed
benchmark: recreate benchmarks
1 parent e4ad768 commit d4f4bd5

File tree

7 files changed

+344
-28
lines changed

7 files changed

+344
-28
lines changed

benchmark/json/json-parser.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
'use strict';
22
const { readFile } = require('node:fs/promises');
33
const common = require('../common.js');
4-
const { parse, parseFromBuffer } = require('node:json');
4+
const { parse } = require('node:json');
55
const path = require('node:path');
66

77
const configs = {
88
n: [1024],
9-
encoding: ['utf-8', 'buffer'],
9+
parser: ['native', 'node'],
10+
input: ['simple-array', 'simple-object', 'nested-ascii', 'nested-unicode', 'twitter'],
1011
};
1112

1213
const bench = common.createBenchmark(main, configs);
1314

1415
async function main(conf) {
15-
const fn = conf.encoding === 'buffer' ? parseFromBuffer : parse;
16+
const fn = conf.parser === 'native' ? JSON.parse : parse;
1617

17-
const enconding = conf.encoding === 'buffer' ? undefined : conf.encoding;
18-
const json = await readFile(path.join(__dirname, 'twitter.json'), enconding);
18+
const filename = `${conf.input}.json`;
19+
const json = await readFile(path.join(__dirname, filename), 'utf-8');
1920

2021
bench.start();
2122

benchmark/json/json-v8-parser.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

benchmark/json/nested-ascii.json

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"users": [
3+
{
4+
"id": 1,
5+
"name": "Alice Johnson",
6+
"profile": {
7+
"email": "alice@example.com",
8+
"age": 28,
9+
"address": {
10+
"street": "456 Oak Ave",
11+
"city": "Boston",
12+
"state": "MA",
13+
"zip": "02101",
14+
"coordinates": {
15+
"lat": 42.3601,
16+
"lng": -71.0589
17+
}
18+
},
19+
"preferences": {
20+
"notifications": true,
21+
"theme": "dark",
22+
"language": "en"
23+
}
24+
},
25+
"posts": [
26+
{
27+
"id": 101,
28+
"title": "First Post",
29+
"content": "Hello world!",
30+
"tags": ["intro", "welcome"],
31+
"likes": 42,
32+
"comments": [
33+
{"user": "bob", "text": "Great post!", "timestamp": 1609459200},
34+
{"user": "charlie", "text": "Welcome!", "timestamp": 1609462800}
35+
]
36+
},
37+
{
38+
"id": 102,
39+
"title": "Second Post",
40+
"content": "Another update",
41+
"tags": ["update", "news"],
42+
"likes": 87,
43+
"comments": []
44+
}
45+
]
46+
},
47+
{
48+
"id": 2,
49+
"name": "Bob Smith",
50+
"profile": {
51+
"email": "bob@example.com",
52+
"age": 35,
53+
"address": {
54+
"street": "789 Pine Rd",
55+
"city": "Seattle",
56+
"state": "WA",
57+
"zip": "98101",
58+
"coordinates": {
59+
"lat": 47.6062,
60+
"lng": -122.3321
61+
}
62+
},
63+
"preferences": {
64+
"notifications": false,
65+
"theme": "light",
66+
"language": "en"
67+
}
68+
},
69+
"posts": [
70+
{
71+
"id": 201,
72+
"title": "Tech Talk",
73+
"content": "Discussing new technologies",
74+
"tags": ["tech", "discussion"],
75+
"likes": 156,
76+
"comments": [
77+
{"user": "alice", "text": "Interesting!", "timestamp": 1609466400}
78+
]
79+
}
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"version": "1.0",
85+
"timestamp": 1609459200,
86+
"total": 2,
87+
"cached": false
88+
}
89+
}

benchmark/json/nested-unicode.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"utilisateurs": [
3+
{
4+
"id": 1,
5+
"nom": "Marie Dubois",
6+
"profil": {
7+
"courriel": "marie@exemple.fr",
8+
"âge": 28,
9+
"adresse": {
10+
"rue": "123 Rue de la Paix",
11+
"ville": "Paris",
12+
"pays": "France",
13+
"code": "75001",
14+
"coordonnées": {
15+
"lat": 48.8566,
16+
"lng": 2.3522
17+
}
18+
},
19+
"préférences": {
20+
"notifications": true,
21+
"thème": "sombre",
22+
"langue": "fr"
23+
}
24+
},
25+
"publications": [
26+
{
27+
"id": 101,
28+
"titre": "Première publication",
29+
"contenu": "Bonjour le monde! 🌍",
30+
"étiquettes": [
31+
"intro",
32+
"bienvenue"
33+
],
34+
"mentions": 42,
35+
"commentaires": [
36+
{
37+
"utilisateur": "jean",
38+
"texte": "Excellent! 👍",
39+
"horodatage": 1609459200
40+
},
41+
{
42+
"utilisateur": "sophie",
43+
"texte": "Bienvenue! 🎉",
44+
"horodatage": 1609462800
45+
}
46+
]
47+
}
48+
]
49+
},
50+
{
51+
"id": 2,
52+
"nom": "田中太郎",
53+
"profil": {
54+
"courriel": "tanaka@example.jp",
55+
"âge": 35,
56+
"adresse": {
57+
"rue": "東京都渋谷区1-2-3",
58+
"ville": "東京",
59+
"pays": "日本",
60+
"code": "150-0001",
61+
"coordonnées": {
62+
"lat": 35.6762,
63+
"lng": 139.6503
64+
}
65+
},
66+
"préférences": {
67+
"notifications": false,
68+
"thème": "明るい",
69+
"langue": "ja"
70+
}
71+
},
72+
"publications": [
73+
{
74+
"id": 201,
75+
"titre": "技術について",
76+
"contenu": "新しい技術を議論しています",
77+
"étiquettes": [
78+
"技術",
79+
"議論"
80+
],
81+
"mentions": 156,
82+
"commentaires": [
83+
{
84+
"utilisateur": "山田",
85+
"texte": "興味深い! ⭐",
86+
"horodatage": 1609466400
87+
}
88+
]
89+
}
90+
]
91+
},
92+
{
93+
"id": 3,
94+
"nom": "Иван Петров",
95+
"profil": {
96+
"courriel": "ivan@example.ru",
97+
"âge": 32,
98+
"adresse": {
99+
"rue": "Невский проспект 123",
100+
"ville": "Санкт-Петербург",
101+
"pays": "Россия",
102+
"code": "190000",
103+
"coordonnées": {
104+
"lat": 59.9343,
105+
"lng": 30.3351
106+
}
107+
},
108+
"préférences": {
109+
"notifications": true,
110+
"thème": "тёмная",
111+
"langue": "ru"
112+
}
113+
},
114+
"publications": []
115+
}
116+
],
117+
"métadonnées": {
118+
"version": "1.0",
119+
"horodatage": 1609459200,
120+
"total": 3,
121+
"mis_en_cache": false,
122+
"description": "Données avec caractères Unicode: émojis 😀, alphabets cyrilliques Й, japonais 漢字, et accents français é"
123+
}
124+
}

benchmark/json/simple-array.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[
2+
1,
3+
2,
4+
3,
5+
4,
6+
5,
7+
6,
8+
7,
9+
8,
10+
9,
11+
10,
12+
11,
13+
12,
14+
13,
15+
14,
16+
15,
17+
16,
18+
17,
19+
18,
20+
19,
21+
20,
22+
21,
23+
22,
24+
23,
25+
24,
26+
25,
27+
26,
28+
27,
29+
28,
30+
29,
31+
30,
32+
31,
33+
32,
34+
33,
35+
34,
36+
35,
37+
36,
38+
37,
39+
38,
40+
39,
41+
40,
42+
41,
43+
42,
44+
43,
45+
44,
46+
45,
47+
46,
48+
47,
49+
48,
50+
49,
51+
50,
52+
51,
53+
52,
54+
53,
55+
54,
56+
55,
57+
56,
58+
57,
59+
58,
60+
59,
61+
60,
62+
61,
63+
62,
64+
63,
65+
64,
66+
65,
67+
66,
68+
67,
69+
68,
70+
69,
71+
70,
72+
71,
73+
72,
74+
73,
75+
74,
76+
75,
77+
76,
78+
77,
79+
78,
80+
79,
81+
80,
82+
81,
83+
82,
84+
83,
85+
84,
86+
85,
87+
86,
88+
87,
89+
88,
90+
89,
91+
90,
92+
91,
93+
92,
94+
93,
95+
94,
96+
95,
97+
96,
98+
97,
99+
98,
100+
99,
101+
100
102+
]

benchmark/json/simple-object.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"id": 12345,
3+
"name": "John Doe",
4+
"email": "john.doe@example.com",
5+
"age": 30,
6+
"active": true,
7+
"balance": 1234.56,
8+
"address": "123 Main St",
9+
"city": "New York",
10+
"state": "NY",
11+
"zip": "10001",
12+
"country": "USA",
13+
"phone": "+1-555-1234",
14+
"website": "https://example.com",
15+
"company": "Acme Corp",
16+
"role": "Developer",
17+
"department": "Engineering",
18+
"salary": 75000,
19+
"hired": "2020-01-15",
20+
"verified": true,
21+
"score": 98.5
22+
}

0 commit comments

Comments
 (0)