Skip to content

Instantly share code, notes, and snippets.

@anuraaga
Created October 27, 2020 08:20
Show Gist options
  • Save anuraaga/2f2187cf1886197b5d65c2018001750d to your computer and use it in GitHub Desktop.
Save anuraaga/2f2187cf1886197b5d65c2018001750d to your computer and use it in GitHub Desktop.
ContextBenchmark - array
Benchmark (size) Mode Cnt Score Error Units
ContextBenchmark.readAll 2 thrpt 5 59879.753 ± 7899.794 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 2 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 2 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readAll:·gc.count 2 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 3 thrpt 5 50794.621 ± 7431.335 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 3 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 3 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readAll:·gc.count 3 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 4 thrpt 5 38020.107 ± 2920.804 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 4 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 4 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readAll:·gc.count 4 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 5 thrpt 5 27095.095 ± 5104.976 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 5 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 5 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readAll:·gc.count 5 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 10 thrpt 5 12135.213 ± 908.001 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 10 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 10 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.readAll:·gc.count 10 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 20 thrpt 5 5097.638 ± 432.923 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 20 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 20 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.readAll:·gc.count 20 thrpt 5 ≈ 0 counts
ContextBenchmark.readAll 40 thrpt 5 1806.476 ± 469.607 ops/ms
ContextBenchmark.readAll:·gc.alloc.rate 40 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readAll:·gc.alloc.rate.norm 40 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.readAll:·gc.count 40 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 2 thrpt 5 183345.232 ± 13472.219 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 2 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 2 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 2 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 3 thrpt 5 183449.394 ± 15214.254 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 3 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 3 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 3 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 4 thrpt 5 181446.264 ± 22109.375 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 4 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 4 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 4 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 5 thrpt 5 175718.889 ± 11907.852 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 5 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 5 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 5 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 10 thrpt 5 181165.728 ± 15173.090 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 10 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 10 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 10 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 20 thrpt 5 182313.142 ± 27246.804 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 20 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 20 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 20 thrpt 5 ≈ 0 counts
ContextBenchmark.readFirst 40 thrpt 5 188675.193 ± 10642.232 ops/ms
ContextBenchmark.readFirst:·gc.alloc.rate 40 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readFirst:·gc.alloc.rate.norm 40 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readFirst:·gc.count 40 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 2 thrpt 5 143968.969 ± 23163.705 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 2 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 2 thrpt 5 ≈ 10⁻⁶ B/op
ContextBenchmark.readLast:·gc.count 2 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 3 thrpt 5 129825.208 ± 11045.424 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 3 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 3 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 3 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 4 thrpt 5 110637.906 ± 7251.757 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 4 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 4 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 4 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 5 thrpt 5 128459.625 ± 15474.235 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 5 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 5 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 5 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 10 thrpt 5 90810.030 ± 6930.142 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 10 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 10 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 10 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 20 thrpt 5 64998.895 ± 2639.550 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 20 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 20 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 20 thrpt 5 ≈ 0 counts
ContextBenchmark.readLast 40 thrpt 5 51271.435 ± 2687.410 ops/ms
ContextBenchmark.readLast:·gc.alloc.rate 40 thrpt 5 ≈ 10⁻⁴ MB/sec
ContextBenchmark.readLast:·gc.alloc.rate.norm 40 thrpt 5 ≈ 10⁻⁵ B/op
ContextBenchmark.readLast:·gc.count 40 thrpt 5 ≈ 0 counts
ContextBenchmark.writeAll 2 thrpt 5 27534.734 ± 2841.617 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 2 thrpt 5 1536.366 ± 156.348 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 2 thrpt 5 88.010 ± 0.002 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 2 thrpt 5 1525.888 ± 297.727 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 2 thrpt 5 87.420 ± 15.729 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 2 thrpt 5 0.007 ± 0.007 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 2 thrpt 5 ≈ 10⁻³ B/op
ContextBenchmark.writeAll:·gc.count 2 thrpt 5 52.000 counts
ContextBenchmark.writeAll:·gc.time 2 thrpt 5 33.000 ms
ContextBenchmark.writeAll 3 thrpt 5 17322.508 ± 1503.691 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 3 thrpt 5 1583.703 ± 150.655 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 3 thrpt 5 144.016 ± 0.002 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 3 thrpt 5 1587.201 ± 253.388 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 3 thrpt 5 144.317 ± 16.277 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 3 thrpt 5 0.007 ± 0.012 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 3 thrpt 5 0.001 ± 0.001 B/op
ContextBenchmark.writeAll:·gc.count 3 thrpt 5 54.000 counts
ContextBenchmark.writeAll:·gc.time 3 thrpt 5 34.000 ms
ContextBenchmark.writeAll 4 thrpt 5 12933.913 ± 974.274 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 4 thrpt 5 1703.858 ± 120.854 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 4 thrpt 5 208.020 ± 0.004 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 4 thrpt 5 1692.705 ± 381.127 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 4 thrpt 5 206.655 ± 43.951 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 4 thrpt 5 0.006 ± 0.008 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 4 thrpt 5 0.001 ± 0.001 B/op
ContextBenchmark.writeAll:·gc.count 4 thrpt 5 48.000 counts
ContextBenchmark.writeAll:·gc.time 4 thrpt 5 33.000 ms
ContextBenchmark.writeAll 5 thrpt 5 10239.561 ± 758.713 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 5 thrpt 5 1819.818 ± 133.090 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 5 thrpt 5 280.027 ± 0.005 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 5 thrpt 5 1835.755 ± 383.249 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 5 thrpt 5 282.464 ± 53.434 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 5 thrpt 5 0.008 ± 0.018 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 5 thrpt 5 0.001 ± 0.003 B/op
ContextBenchmark.writeAll:·gc.count 5 thrpt 5 52.000 counts
ContextBenchmark.writeAll:·gc.time 5 thrpt 5 34.000 ms
ContextBenchmark.writeAll 10 thrpt 5 4534.004 ± 269.809 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 10 thrpt 5 2185.417 ± 136.785 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 10 thrpt 5 760.072 ± 0.011 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 10 thrpt 5 2190.441 ± 375.085 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 10 thrpt 5 761.777 ± 115.970 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 10 thrpt 5 0.008 ± 0.014 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 10 thrpt 5 0.003 ± 0.005 B/op
ContextBenchmark.writeAll:·gc.count 10 thrpt 5 62.000 counts
ContextBenchmark.writeAll:·gc.time 10 thrpt 5 43.000 ms
ContextBenchmark.writeAll 20 thrpt 5 2341.644 ± 266.027 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 20 thrpt 5 3441.965 ± 399.468 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 20 thrpt 5 2320.173 ± 0.026 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 20 thrpt 5 3446.961 ± 768.159 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 20 thrpt 5 2322.596 ± 346.643 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 20 thrpt 5 0.010 ± 0.017 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 20 thrpt 5 0.007 ± 0.011 B/op
ContextBenchmark.writeAll:·gc.count 20 thrpt 5 77.000 counts
ContextBenchmark.writeAll:·gc.time 20 thrpt 5 52.000 ms
ContextBenchmark.writeAll 40 thrpt 5 841.970 ± 77.896 ops/ms
ContextBenchmark.writeAll:·gc.alloc.rate 40 thrpt 5 4185.796 ± 407.624 MB/sec
ContextBenchmark.writeAll:·gc.alloc.rate.norm 40 thrpt 5 7840.543 ± 0.054 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space 40 thrpt 5 4170.289 ± 474.234 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Eden_Space.norm 40 thrpt 5 7812.912 ± 777.936 B/op
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space 40 thrpt 5 0.014 ± 0.016 MB/sec
ContextBenchmark.writeAll:·gc.churn.G1_Survivor_Space.norm 40 thrpt 5 0.027 ± 0.030 B/op
ContextBenchmark.writeAll:·gc.count 40 thrpt 5 87.000 counts
ContextBenchmark.writeAll:·gc.time 40 thrpt 5 64.000 ms
ContextBenchmark.writeOne 2 thrpt 5 71840.288 ± 6246.718 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 2 thrpt 5 1821.580 ± 161.954 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 2 thrpt 5 40.004 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 2 thrpt 5 1837.260 ± 383.052 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 2 thrpt 5 40.335 ± 6.071 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 2 thrpt 5 0.006 ± 0.008 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 2 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 2 thrpt 5 52.000 counts
ContextBenchmark.writeOne:·gc.time 2 thrpt 5 35.000 ms
ContextBenchmark.writeOne 3 thrpt 5 68125.040 ± 11396.655 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 3 thrpt 5 1729.046 ± 296.612 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 3 thrpt 5 40.005 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 3 thrpt 5 1732.760 ± 266.307 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 3 thrpt 5 40.103 ± 3.171 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 3 thrpt 5 0.010 ± 0.009 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 3 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 3 thrpt 5 59.000 counts
ContextBenchmark.writeOne:·gc.time 3 thrpt 5 34.000 ms
ContextBenchmark.writeOne 4 thrpt 5 72026.550 ± 3546.762 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 4 thrpt 5 1828.054 ± 97.390 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 4 thrpt 5 40.004 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 4 thrpt 5 1834.176 ± 378.492 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 4 thrpt 5 40.131 ± 7.286 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 4 thrpt 5 0.008 ± 0.005 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 4 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 4 thrpt 5 52.000 counts
ContextBenchmark.writeOne:·gc.time 4 thrpt 5 35.000 ms
ContextBenchmark.writeOne 5 thrpt 5 70083.739 ± 5462.773 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 5 thrpt 5 1777.888 ± 132.264 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 5 thrpt 5 40.005 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 5 thrpt 5 1791.074 ± 240.771 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 5 thrpt 5 40.293 ± 2.674 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 5 thrpt 5 0.010 ± 0.007 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 5 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 5 thrpt 5 61.000 counts
ContextBenchmark.writeOne:·gc.time 5 thrpt 5 38.000 ms
ContextBenchmark.writeOne 10 thrpt 5 71003.001 ± 2672.873 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 10 thrpt 5 1800.538 ± 75.071 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 10 thrpt 5 40.004 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 10 thrpt 5 1799.309 ± 301.265 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 10 thrpt 5 39.977 ± 6.504 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 10 thrpt 5 0.008 ± 0.011 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 10 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 10 thrpt 5 51.000 counts
ContextBenchmark.writeOne:·gc.time 10 thrpt 5 34.000 ms
ContextBenchmark.writeOne 20 thrpt 5 70877.570 ± 6492.215 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 20 thrpt 5 1797.180 ± 166.334 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 20 thrpt 5 40.004 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 20 thrpt 5 1800.735 ± 306.193 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 20 thrpt 5 40.079 ± 4.971 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 20 thrpt 5 0.008 ± 0.013 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 20 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 20 thrpt 5 51.000 counts
ContextBenchmark.writeOne:·gc.time 20 thrpt 5 33.000 ms
ContextBenchmark.writeOne 40 thrpt 5 70640.188 ± 1855.223 ops/ms
ContextBenchmark.writeOne:·gc.alloc.rate 40 thrpt 5 1791.120 ± 60.873 MB/sec
ContextBenchmark.writeOne:·gc.alloc.rate.norm 40 thrpt 5 40.004 ± 0.001 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space 40 thrpt 5 1801.710 ± 311.162 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Eden_Space.norm 40 thrpt 5 40.238 ± 6.473 B/op
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space 40 thrpt 5 0.007 ± 0.010 MB/sec
ContextBenchmark.writeOne:·gc.churn.G1_Survivor_Space.norm 40 thrpt 5 ≈ 10⁻⁴ B/op
ContextBenchmark.writeOne:·gc.count 40 thrpt 5 51.000 counts
ContextBenchmark.writeOne:·gc.time 40 thrpt 5 33.000 ms
@anuraaga
Copy link
Author

anuraaga commented Oct 27, 2020

final class DefaultContext implements Context {

  static final Context ROOT = new DefaultContext();

  /**
   * Returns the default {@link ContextStorage} used to attach {@link Context}s to scopes of
   * execution. Should only be used when defining your own {@link ContextStorage} in case you want
   * to delegate functionality to the default implementation.
   */
  static ContextStorage threadLocalStorage() {
    return ThreadLocalContextStorage.INSTANCE;
  }

  private final Object[] entries;

  private DefaultContext(Object[] entries) {
    this.entries = entries;
  }

  DefaultContext() {
    entries = new Object[0];
  }

  @Override
  @Nullable
  public <V> V get(ContextKey<V> key) {
    int valueIndex = valueIndex(key);
    if (valueIndex == -1) {
      return null;
    }
    // Because withValue enforces the value for a key is its type, this is always safe.
    @SuppressWarnings("unchecked")
    V value = (V) entries[valueIndex];
    return value;
  }

  @Override
  public <V> Context with(ContextKey<V> k1, V v1) {
    int valueIndex = valueIndex(k1);
    final Object[] newEntries;
    if (valueIndex != -1) {
      newEntries = entries.clone();
      newEntries[valueIndex] = v1;
    } else {
      newEntries = Arrays.copyOf(entries, entries.length + 2);
      newEntries[newEntries.length - 2] = k1;
      newEntries[newEntries.length - 1] = v1;
    }
    return new DefaultContext(newEntries);
  }

  private int valueIndex(ContextKey<?> key) {
    for (int i = 0; i < entries.length; i += 2) {
      if (entries[i] == key) {
        return i + 1;
      }
    }
    return -1;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment