Skip to content
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
46 changes: 46 additions & 0 deletions benchmark/json/json-buffer-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';
const { readFile } = require('node:fs/promises');
const common = require('../common.js');
const { parseFromBuffer } = require('node:json');
const path = require('node:path');
const assert = require('node:assert');

const configs = {
n: [10, 1024],
parser: ['native', 'node'],
input: [
'simple-string',
'simple-number-array',
'simple-string-array',
'simple-object',
'nested-ascii',
'nested-unicode',
'twitter',
],
};

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

async function main(conf) {
function parseNative(buf) {
return JSON.parse(buf.toString());
}

function parseNode(buf) {
return parseFromBuffer(buf);
}

const fn = conf.parser === 'native' ? parseNative : parseNode;

const filename = `${conf.input}.json`;
const json = await readFile(path.join(__dirname, filename));

let deadcode;
bench.start();
for (let i = 0; i < conf.n; i++) {
deadcode = fn(json);
}
bench.end(conf.n);

assert.ok(deadcode);
}
28 changes: 28 additions & 0 deletions benchmark/json/json-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const { readFile } = require('node:fs/promises');
const common = require('../common.js');
const { parse } = require('node:json');
const path = require('node:path');

const configs = {
n: [10],
parser: ['native', 'node'],
input: ['simple-array', 'simple-object', 'nested-ascii', 'nested-unicode', 'twitter'],
};

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

async function main(conf) {
const fn = conf.parser === 'native' ? JSON.parse : parse;

const filename = `${conf.input}.json`;
const json = await readFile(path.join(__dirname, filename), 'utf-8');

bench.start();

for (let i = 0; i < conf.n; i++) {
fn(json);
}

bench.end(conf.n);
}
89 changes: 89 additions & 0 deletions benchmark/json/nested-ascii.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"users": [
{
"id": 1,
"name": "Alice Johnson",
"profile": {
"email": "alice@example.com",
"age": 28,
"address": {
"street": "456 Oak Ave",
"city": "Boston",
"state": "MA",
"zip": "02101",
"coordinates": {
"lat": 42.3601,
"lng": -71.0589
}
},
"preferences": {
"notifications": true,
"theme": "dark",
"language": "en"
}
},
"posts": [
{
"id": 101,
"title": "First Post",
"content": "Hello world!",
"tags": ["intro", "welcome"],
"likes": 42,
"comments": [
{"user": "bob", "text": "Great post!", "timestamp": 1609459200},
{"user": "charlie", "text": "Welcome!", "timestamp": 1609462800}
]
},
{
"id": 102,
"title": "Second Post",
"content": "Another update",
"tags": ["update", "news"],
"likes": 87,
"comments": []
}
]
},
{
"id": 2,
"name": "Bob Smith",
"profile": {
"email": "bob@example.com",
"age": 35,
"address": {
"street": "789 Pine Rd",
"city": "Seattle",
"state": "WA",
"zip": "98101",
"coordinates": {
"lat": 47.6062,
"lng": -122.3321
}
},
"preferences": {
"notifications": false,
"theme": "light",
"language": "en"
}
},
"posts": [
{
"id": 201,
"title": "Tech Talk",
"content": "Discussing new technologies",
"tags": ["tech", "discussion"],
"likes": 156,
"comments": [
{"user": "alice", "text": "Interesting!", "timestamp": 1609466400}
]
}
]
}
],
"metadata": {
"version": "1.0",
"timestamp": 1609459200,
"total": 2,
"cached": false
}
}
124 changes: 124 additions & 0 deletions benchmark/json/nested-unicode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"utilisateurs": [
{
"id": 1,
"nom": "Marie Dubois",
"profil": {
"courriel": "marie@exemple.fr",
"âge": 28,
"adresse": {
"rue": "123 Rue de la Paix",
"ville": "Paris",
"pays": "France",
"code": "75001",
"coordonnées": {
"lat": 48.8566,
"lng": 2.3522
}
},
"préférences": {
"notifications": true,
"thème": "sombre",
"langue": "fr"
}
},
"publications": [
{
"id": 101,
"titre": "Première publication",
"contenu": "Bonjour le monde! 🌍",
"étiquettes": [
"intro",
"bienvenue"
],
"mentions": 42,
"commentaires": [
{
"utilisateur": "jean",
"texte": "Excellent! 👍",
"horodatage": 1609459200
},
{
"utilisateur": "sophie",
"texte": "Bienvenue! 🎉",
"horodatage": 1609462800
}
]
}
]
},
{
"id": 2,
"nom": "田中太郎",
"profil": {
"courriel": "tanaka@example.jp",
"âge": 35,
"adresse": {
"rue": "東京都渋谷区1-2-3",
"ville": "東京",
"pays": "日本",
"code": "150-0001",
"coordonnées": {
"lat": 35.6762,
"lng": 139.6503
}
},
"préférences": {
"notifications": false,
"thème": "明るい",
"langue": "ja"
}
},
"publications": [
{
"id": 201,
"titre": "技術について",
"contenu": "新しい技術を議論しています",
"étiquettes": [
"技術",
"議論"
],
"mentions": 156,
"commentaires": [
{
"utilisateur": "山田",
"texte": "興味深い! ⭐",
"horodatage": 1609466400
}
]
}
]
},
{
"id": 3,
"nom": "Иван Петров",
"profil": {
"courriel": "ivan@example.ru",
"âge": 32,
"adresse": {
"rue": "Невский проспект 123",
"ville": "Санкт-Петербург",
"pays": "Россия",
"code": "190000",
"coordonnées": {
"lat": 59.9343,
"lng": 30.3351
}
},
"préférences": {
"notifications": true,
"thème": "тёмная",
"langue": "ru"
}
},
"publications": []
}
],
"métadonnées": {
"version": "1.0",
"horodatage": 1609459200,
"total": 3,
"mis_en_cache": false,
"description": "Données avec caractères Unicode: émojis 😀, alphabets cyrilliques Й, japonais 漢字, et accents français é"
}
}
102 changes: 102 additions & 0 deletions benchmark/json/simple-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100
]
Loading