Skip to content

Commit dd9326a

Browse files
Copilothossain-khan
andcommitted
Update benchmark README and clean up test files
Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
1 parent 363c6de commit dd9326a

File tree

2 files changed

+36
-69
lines changed

2 files changed

+36
-69
lines changed

benchmark/README.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# JSON5 vs JSON Performance Benchmark
1+
# JSON5 Performance Benchmark - Three-way Comparison
22

3-
This module provides benchmarking tools to compare the performance of JSON5 serialization/deserialization against standard JSON using kotlinx.serialization.
3+
This module provides benchmarking tools to compare the performance of JSON5 serialization/deserialization across three different implementations:
4+
5+
1. **JSON5** (this project) - Uses kotlinx.serialization
6+
2. **JSON** (kotlinx.serialization) - Standard JSON baseline
7+
3. **External-JSON5** (at.syntaxerror.json5:2.1.0) - External JSON5 library
48

59
## Running the Benchmark
610

@@ -27,9 +31,9 @@ The benchmark generates two types of reports:
2731

2832
### Summary Report
2933
- File: `benchmark_summary_YYYY-MM-DD_HH-mm-ss.txt`
30-
- Contains human-readable performance comparisons
31-
- Shows which format is faster and by how much
32-
- Includes overall statistics
34+
- Contains human-readable performance comparisons across all three libraries
35+
- Shows relative performance comparisons between each pair of libraries
36+
- Includes overall statistics and rankings
3337

3438
## Test Data Types
3539

@@ -59,39 +63,37 @@ To run the benchmark module tests:
5963

6064
## Sample Results
6165

62-
Based on typical runs, JSON standard library generally performs 2-6x faster than JSON5 for both serialization and deserialization, with the performance gap being larger for more complex data structures.
66+
Based on typical runs across the three libraries:
67+
68+
- **JSON** (kotlinx.serialization) is consistently the fastest
69+
- **External-JSON5** performs better than this project's JSON5 implementation
70+
- **JSON5** (this project) offers kotlinx.serialization integration but with slower performance
6371

6472
Example output:
6573
```
66-
SimplePerson Serialization: JSON5=0.027ms, JSON=0.013ms
67-
ComplexPerson Serialization: JSON5=0.083ms, JSON=0.015ms
68-
Company Serialization: JSON5=0.200ms, JSON=0.032ms
74+
SimplePerson Serialization: JSON5=0.028ms, JSON=0.010ms, External-JSON5=0.011ms
75+
ComplexPerson Serialization: JSON5=0.073ms, JSON=0.018ms, External-JSON5=0.018ms
76+
Company Serialization: JSON5=0.163ms, JSON=0.031ms, External-JSON5=0.054ms
6977
```
7078

7179
### Benchmark Result Snapshot
7280

73-
| Case | Type | JSON5 Avg (ms) | JSON Avg (ms) | Speedup (JSON) |
74-
| ------------------- | --------------- | -------------- | ------------- | -------------- |
75-
| SimplePerson | Serialization | 0.056 | 0.020 | 2.77× |
76-
| SimplePerson | Deserialization | 0.064 | 0.022 | 2.93× |
77-
| ComplexPerson | Serialization | 0.089 | 0.019 | 4.59× |
78-
| ComplexPerson | Deserialization | 0.113 | 0.030 | 3.76× |
79-
| Company | Serialization | 0.226 | 0.059 | 3.81× |
80-
| Company | Deserialization | 0.254 | 0.090 | 2.83× |
81-
| NumberTypes | Serialization | 0.032 | 0.003 | 9.43× |
82-
| NumberTypes | Deserialization | 0.021 | 0.003 | 6.60× |
83-
| CollectionTypes | Serialization | 0.067 | 0.009 | 7.41× |
84-
| CollectionTypes | Deserialization | 0.059 | 0.025 | 2.37× |
85-
| SimplePersonList100 | Serialization | 0.153 | 0.042 | 3.64× |
86-
| SimplePersonList100 | Deserialization | 0.234 | 0.039 | 5.99× |
87-
| ComplexPersonList50 | Serialization | 0.388 | 0.059 | 6.59× |
88-
| ComplexPersonList50 | Deserialization | 0.452 | 0.089 | 5.09× |
89-
90-
**Overall Average Time**
91-
92-
* JSON5: **0.158 ms**
93-
* JSON: **0.036 ms**
94-
* 🔥 Overall: **KotlinX JSON is 4.33× faster than JSON5**
95-
96-
97-
<img width="800" alt="benchmark bar chart" src="https://github.com/user-attachments/assets/bcf44217-827b-49a1-a18b-4a0f7fedc103" />
81+
| Case | Type | JSON5 (ms) | JSON (ms) | External-JSON5 (ms) | Performance Ranking |
82+
| ------------------- | --------------- | ---------- | --------- | ------------------- | ------------------- |
83+
| SimplePerson | Serialization | 0.028 | 0.010 | 0.011 | JSON > Ext-JSON5 > JSON5 |
84+
| SimplePerson | Deserialization | 0.049 | 0.014 | 0.017 | JSON > Ext-JSON5 > JSON5 |
85+
| ComplexPerson | Serialization | 0.073 | 0.018 | 0.018 | JSON ≈ Ext-JSON5 > JSON5 |
86+
| ComplexPerson | Deserialization | 0.101 | 0.021 | 0.020 | Ext-JSON5 > JSON > JSON5 |
87+
| Company | Serialization | 0.163 | 0.031 | 0.054 | JSON > Ext-JSON5 > JSON5 |
88+
| Company | Deserialization | 0.200 | 0.081 | 0.117 | JSON > Ext-JSON5 > JSON5 |
89+
90+
**Overall Performance Comparison:**
91+
- **JSON** is **3.90×** faster than **JSON5** and **2.75×** faster than **External-JSON5**
92+
- **External-JSON5** is **1.42×** faster than **JSON5**
93+
94+
## Key Insights
95+
96+
- **kotlinx.serialization JSON** remains the performance leader
97+
- **External JSON5 library** provides a good balance of JSON5 features with reasonable performance
98+
- **This project's JSON5** offers seamless kotlinx.serialization integration but at a performance cost
99+
- Choose based on your priorities: performance (JSON), JSON5 features with good performance (External-JSON5), or kotlinx.serialization integration (this project)

benchmark/src/main/kotlin/dev/hossain/json5kt/benchmark/test/ExternalJson5Test.kt

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

0 commit comments

Comments
 (0)