|
1 | | -# ParserNG Performance Benchmarks |
| 1 | +# ParserNG 1.0.0 Official Benchmarks |
| 2 | + |
| 3 | +The following data represents high-concurrency performance and memory allocation benchmarks for **ParserNG**, compared against **Janino** (Bytecode Compiler) and **exp4j** (Interpreted). |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +### 🖥️ Environment Specifications |
| 8 | +* **JMH Version:** 1.37 |
| 9 | +* **JDK:** 24.0.1 (Java HotSpot(TM) 64-Bit Server VM, 24.0.1+9-30) |
| 10 | +* **Memory:** -Xms2g -Xmx2g |
| 11 | +* **Platform:** Windows 10 / x64 |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +### 🚀 Performance Benchmarks (Latency) |
| 16 | +*Lower scores indicate higher speed.* |
| 17 | + |
| 18 | +#### **Scenario A: Standard Power & Root** |
| 19 | +**Expression:** `(x^2 + y^0.5)^4.2` |
| 20 | + |
| 21 | +| Benchmark | Mode | Score (ns/op) | Error (±) | |
| 22 | +| :--- | :---: | :--- | :--- | |
| 23 | +| **ParserNG Turbo** | avgt | **89.093** | 0.951 | |
| 24 | +| Janino | avgt | 103.924 | 10.833 | |
| 25 | +| ParserNG (Standard) | avgt | 123.724 | 8.477 | |
| 26 | +| exp4j | avgt | 220.926 | 5.717 | |
2 | 27 |
|
3 | | -## Test Results (JMH, JDK 24.0.1) |
| 28 | +#### **Scenario B: Complex Nested Logic** |
| 29 | +**Expression:** `((x^2 + 3*sin(x+5^3-1/4)) / (23/33 + cos(x^2))) * (exp(x) / 10) + (sin(3) + cos(4 - sin(2))) ^ (-2)` |
4 | 30 |
|
5 | | -### Benchmark Setup |
6 | | -- **Expression**: Generic floating-point math |
7 | | -- **Iterations**: 5 runs, 1000ms each measurement |
8 | | -- **VM Options**: -Xms2g -Xmx2g (Test 1) and defaults (Test 2) |
| 31 | +| Benchmark | Mode | Score (ns/op) | Error (±) | |
| 32 | +| :--- | :---: | :--- | :--- | |
| 33 | +| **ParserNG Turbo** | avgt | **85.399** | 0.933 | |
| 34 | +| Janino | avgt | 249.981 | 7.411 | |
| 35 | +| ParserNG (Standard) | avgt | 323.650 | 20.661 | |
| 36 | +| exp4j | avgt | 805.753 | 123.264 | |
9 | 37 |
|
10 | | -### Results |
| 38 | +--- |
11 | 39 |
|
12 | | -Real JMH benchmarks |
| 40 | +### ⚡ Constant Folding Impact |
| 41 | +**Expression:** `(sin(8+cos(3)) + 2 + ((27-5)/(8^3) * (3.14159 * 4^(14-10)) + sin(-3.141) + (0%4)) * 4/3 * 3/sqrt(4))+12` |
13 | 42 |
|
14 | | -#### 1 |
15 | | -``` |
16 | | -Benchmark Test 1 (2GB Heap) Test 2 (Default) Winner |
17 | | -──────────────────────────────────────────────────────────────── |
18 | | -Exp4J 811.6 ns/op 597.3 ns/op |
19 | | -ParserNG 198.3 ns/op 178.0 ns/op ✅ |
20 | | -──────────────────────────────────────────────────────────────── |
21 | | -Speedup Factor 4.1x 3.36x |
22 | | -Consistency (σ) 25 ns (tight) 206 ns (loose) ✅ |
23 | | -``` |
| 43 | +| Benchmark | State | Score (ns/op) | Improvement | |
| 44 | +| :--- | :--- | :--- | :--- | |
| 45 | +| **ParserNG Turbo** | **With Folding** | **10.301** | **~12x Faster** | |
| 46 | +| ParserNG Turbo | Without Folding | 125.410 | Baseline | |
| 47 | +| ParserNG (Std) | **With Folding** | **53.081** | **~9x Faster** | |
| 48 | +| ParserNG (Std) | Without Folding | 477.226 | Baseline | |
24 | 49 |
|
25 | | -#### 2 `(7*x+y)-(3*x*y+4*x)-(4*x-5*y)/(3*x^2-5*y^3)` |
| 50 | +--- |
26 | 51 |
|
27 | | -``` |
28 | | -Benchmark Mode Cnt Score Error Units |
29 | | -ParserNGWars.exp4j avgt 10 687.698 ± 7.916 ns/op |
30 | | -ParserNGWars.parserNg avgt 10 292.933 ± 11.497 ns/op |
31 | | -``` |
| 52 | +### 🧠 Memory & GC Profile (Allocation Rate) |
| 53 | +*Measured using `-prof gc`. "B/op" represents bytes allocated per evaluation.* |
32 | 54 |
|
| 55 | +#### **Scenario: `((x^2 + sin(x)) / (1 + cos(x^2))) * (exp(x) / 10)`** |
33 | 56 |
|
34 | | -#### 3. `sin(7*x+y)+cos(7*x-y)` |
35 | | -``` |
36 | | -Benchmark Mode Cnt Score Error Units |
37 | | -ParserNGWars.exp4j avgt 10 362.020 � 15.825 ns/op |
38 | | -ParserNGWars.parserNg avgt 10 192.830 � 9.271 ns/op |
39 | | -``` |
40 | | -### Key Insights |
| 57 | +| Benchmark | Speed (ns/op) | Alloc Rate (B/op) | GC Efficiency | |
| 58 | +| :--- | :--- | :--- | :--- | |
| 59 | +| **ParserNG Turbo** | **81.204** | **≈ 0.00** | **Garbage-Free** | |
| 60 | +| ParserNG (Standard) | 266.498 | ≈ 0.00 | **Garbage-Free** | |
| 61 | +| Janino | 117.085 | 48.000 | 10+ objects/sec | |
| 62 | +| exp4j | 493.703 | 400.001 | High Pressure | |
41 | 63 |
|
42 | | -1. **ParserNG is 2-4x faster** across all heap configurations |
43 | | -2. **ParserNG is 20x more consistent** (tight error bounds) |
44 | | -3. **ParserNG scales better** with available memory |
45 | | -4. **GC pressure minimal** - low object allocation |
| 64 | +#### **Scenario: `sin(x^3+y^3)-4*(x-y)`** |
46 | 65 |
|
47 | | -### Why ParserNG Wins |
| 66 | +| Benchmark | Speed (ns/op) | Alloc Rate (B/op) | GC Efficiency | |
| 67 | +| :--- | :--- | :--- | :--- | |
| 68 | +| **ParserNG Turbo** | **123.120** | **≈ 0.00** | **Garbage-Free** | |
| 69 | +| ParserNG (Standard) | 188.011 | ≈ 0.00 | **Garbage-Free** | |
| 70 | +| Janino | 147.311 | 48.000 | Constant allocation | |
| 71 | +| exp4j | 366.531 | 320.001 | High Pressure | |
48 | 72 |
|
49 | | -- ✅ Constant folding (`sin(0)` → `0.0`) |
50 | | -- ✅ Strength reduction (`x^2` → `x*x`) |
51 | | -- ✅ Token caching (parse once, evaluate many) |
52 | | -- ✅ Object pooling (reduced GC) |
53 | | -- ✅ DRG mode caching (recompile on switch only) |
54 | | -- ✅ Fast postfix evaluator (direct stack ops) |
| 73 | +--- |
55 | 74 |
|
56 | | -### Recommendations |
| 75 | +### 📊 Summary of Findings |
| 76 | +1. **Turbo Dominance:** ParserNG Turbo consistently outperforms Janino's compiled bytecode by up to **3x** in complex logic scenarios. |
| 77 | +2. **Zero-Allocation:** Unlike competitors, ParserNG maintains a **0 B/op** profile, eliminating GC pauses in high-frequency loops. |
| 78 | +3. **Optimization:** Constant folding in 1.0.0 reduces static expressions to near-instantaneous (10ns) execution. |
57 | 79 |
|
58 | | -- **Production Servers**: Use ParserNG for 3-4x speedup |
59 | | -- **Real-time Systems**: Use ParserNG for predictable latency (σ=25ns) |
60 | | -- **Resource-Constrained**: Use ParserNG (less GC pressure) |
61 | | -- **Mission-Critical**: Use ParserNG (consistent, reliable) |
| 80 | +<br><br> |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + # ANALYSIS |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + ### 📊 Table 1: Raw Evaluation Speed (ns/op) – All Expressions |
| 95 | +**Lower is better** • JMH `avgt` mode • JDK 24 |
62 | 96 |
|
63 | | -### Reproducibility |
| 97 | +| Expression | exp4j (ns/op) | Janino (ns/op) | ParserNG Normal | ParserNG Turbo | Winner | |
| 98 | +|------------|---------------|----------------|-----------------|----------------|--------| |
| 99 | +| `(x² + y⁰·⁵)⁴·²` | 220.9 | 103.9 | 123.7 | **89.1** | **Turbo** | |
| 100 | +| Complex trig + exp + power | 805.8 | 250.0 | 323.7 | **85.4** | **Turbo** | |
| 101 | +| Heavy constants **with** Constant Folding | 755.4 | 185.3 | **53.1** | **10.3** | **Turbo (insane)** | |
| 102 | +| Same expression **without** Constant Folding | 754.6 | 180.8 | 477.2 | **125.4** | **Turbo** | |
64 | 103 |
|
65 | | -Run yourself: |
66 | | -```bash |
67 | | -mvn clean install -DskipTests |
68 | | -java -Xms2g -Xmx2g -jar target/benchmarks.jar |
69 | | -``` |
| 104 | +**Analysis of Table 1** |
| 105 | +ParserNG Turbo dominates every single test. On complex expressions it is **9–10× faster than exp4j** and **2.9–3× faster than Janino**. Even the normal (interpreted) ParserNG beats exp4j on most cases and stays very competitive with Janino. The 10.3 ns/op result with constant folding is outstanding — almost **97 million evaluations per second**. |
70 | 106 |
|
71 | | -Expected result: ParserNG 2-4x faster than Exp4J. |
| 107 | +--- |
| 108 | + |
| 109 | +### 📊 Table 2: Constant Folding Impact (same heavy-constants expression) |
| 110 | + |
| 111 | +| Mode | exp4j | Janino | ParserNG Normal | ParserNG Turbo | |
| 112 | +|-----------------------|---------|---------|-----------------|----------------| |
| 113 | +| **With Constant Folding** | 755.4 | 185.3 | **53.1** | **10.3** | |
| 114 | +| **Without Constant Folding** | 754.6 | 180.8 | 477.2 | **125.4** | |
| 115 | + |
| 116 | +**Analysis of Table 2** |
| 117 | +Enabling constant folding turns ParserNG Normal into a winner already (beats both competitors). Turbo takes it to another level — going from 125 ns → **10.3 ns** (12× speedup just from folding). This shows how powerful ParserNG’s optimiser has become in 1.0.1. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +### 📊 Table 3: Speed + GC Profiling (selected expressions) |
| 122 | + |
| 123 | +| Expression | exp4j (ns/op) | Janino (ns/op) | ParserNG Normal | ParserNG Turbo | |
| 124 | +|------------|---------------|----------------|-----------------|----------------| |
| 125 | +| `((x² + sin(x)) / (1 + cos(x²))) * (exp(x)/10)` | 493.7 | 117.1 | 266.5 | **81.2** | |
| 126 | +| `sin(x³ + y³) - 4*(x - y)` | 366.5 | 147.3 | 188.0 | **123.1** | |
| 127 | + |
| 128 | +**Analysis of Table 3** |
| 129 | +Even under stricter GC profiling runs (longer warmup/measurement), Turbo stays the fastest. ParserNG Normal is consistently faster than exp4j and very close to Janino while offering vastly more features. |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +### 📊 Table 4: Garbage Collection & Memory Usage (JMH `-prof gc`) |
| 134 | + |
| 135 | +| Library | Alloc Rate | Bytes per Operation | GC Count | GC Time (ms) | Memory Winner | |
| 136 | +|------------------|------------------|---------------------|----------|--------------|---------------| |
| 137 | +| **exp4j** | 422 – 864 MB/s | 104 – 400 B/op | 10 – 95 | 49 – 89 | ❌ Heavy | |
| 138 | +| **Janino** | 311 – 456 MB/s | 48 B/op | 10 – 53 | 46 – 53 | ⚠️ Moderate | |
| 139 | +| **ParserNG + Turbo** | **0.001 – 0.007 MB/s** | **≈ 0–1 B/op** | **0** | **0** | **🏆 Zero-allocation** | |
| 140 | + |
| 141 | +**Analysis of Table 4** |
| 142 | +This is ParserNG’s **silent superpower**. While competitors generate hundreds of MB/s of garbage (causing GC pauses), ParserNG + Turbo allocates virtually nothing. In long-running applications, Android, servers, or real-time loops, this advantage often matters more than raw nanoseconds. |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +**Overall Verdict (add this at the bottom)** |
| 147 | + |
| 148 | +> **ParserNG 1.0.1 Turbo is the clear winner** — fastest on every expression, dramatically lower memory pressure, and packed with features the others don’t even have (symbolic diff, resilient integration, matrix algebra, Tartaglia solver, etc.). |
| 149 | +> Whether you use normal mode or Turbo, ParserNG 1.0.1 is now the best pure-Java choice for high-performance math expressions. |
| 150 | +
|
| 151 | + |
0 commit comments