HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
openjdk
jmh
Java2021–2026
openjdk / jmh

jmh

https://openjdk.org/projects/code-tools/jmh

6Distinct people
7Mentions
0Explicit recommenders
2.7KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

https://openjdk.org/projects/code-tools/jmh

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year7 dated mentions

Observed mentions: 2021-01-16 06:27:14 UTC to 2026-10-06 16:34:47 UTC.

0122021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC101
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC000
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC000
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC202
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC202
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC202

What Hacker News says

7 sources
If you are benchmarking Java, there is Java Microbenchmark Harness (https://github.com/openjdk/jmh), which: - Does several warm-up runs so the JIT-optimized code is benchmarked instead of the interpreted code/compilation. - Create multiple forks of the JVM to eliminate JVM run variance. - Provide utilities like `Blackhole` to prevent dead code elimination and `State` to do setup and prevent constant folding.
In Benchmark in Milliseconds
I'd be a bit skeptical of the result given the benchmark program: import java.util.ArrayList; import java.util.List; class Day06 { public static void main(String args[]) { List<String> fileTypeList = new ArrayList<>(); for (int i = 0; i < 1000000; i++) { fileTypeList.add("fileType"); } long beforeForLoop = System.currentTimeMillis(); for (int i = 0; i < fileTypeList.size(); i++) { fileTypeList.get(i); } long afterForLoop = System.currentTimeMillis(); System.out.println("Time took in millis for for " + (afterForLoop - beforeForLoop)); long beforeForeachLoop = System.currentTimeMillis(); for (String s : fileTypeList) { } long af
Read the rest
terForeachLoop = System.currentTimeMillis(); System.out.println("Time took in millis for foreach " + (afterForeachLoop - beforeForeachLoop)); } } Empty loops and no warmup (at a minimum!) make for a somewhat suboptimal benchmark, to say the least. To be honest I'm surprised the JIT didn't eliminate the loops altogether. If you want proper results you probably want to use the Java Microbenchmark Harness [0]. You'd probably want some actual data/work as well so the JIT doesn't overspecialize on the benchmark. Edit: Halfheartedly tried to adapt the LinkedIn benchmark to JMH. Still not a great benchmark and I'm rusty so I wouldn't be surprised if I messed something up, but it's hopefully better the original: package org.sample; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class MyBenchmark { List<String> fileTypeList = new ArrayList<>() {{ for (int i = 0; i < 1000000; i++) { this.add("fileType"); } }}; @Benchmark public void baseline() { } @Benchmark public int measureFor() { int result = 0; for (int i = 0; i < fileTypeList.size(); i++) { result += (int)fileTypeList.get(i).charAt(0); } return result; } @Benchmark public int measureForEach() { int result = 0; for (String s : fileTypeList) { result += (int)s.charAt(0); } return result; } public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(MyBenchmark.class.getSimpleName()) .build(); new Runner(opt).run(); } } And the result summary (run on Ubuntu via WSL2): # JMH version: 1.37 # VM version: JDK 21.0.10, OpenJDK 64-Bit Server VM, 21.0.10+7-Ubuntu-124.04 # VM invoker: /usr/lib/jvm/java-21-openjdk-amd64/bin/java # VM options: <none> # Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable) # Warmup: 5 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op Result "org.sample.MyBenchmark.baseline": 0.254 ±(99.9%) 0.022 ns/op [Average] (min, avg, max) = (0.247, 0.254, 0.262), stdev = 0.006 CI (99.9%): [0.232, 0.276] (assumes normal distribution) Result "org.sample.MyBenchmark.measureFor": 693178.390 ±(99.9%) 60793.583 ns/op [Average] (min, avg, max) = (676266.480, 693178.390, 718114.554), stdev = 15787.901 CI (99.9%): [632384.806, 753971.973] (assumes normal distribution) Result "org.sample.MyBenchmark.measureForEach": 693756.240 ±(99.9%) 7549.769 ns/op [Average] (min, avg, max) = (691685.231, 693756.240, 696573.323), stdev = 1960.651 CI (99.9%): [686206.470, 701306.009] (assumes normal distribution) Doesn't look like a significant difference to me, though obviously the benchmark quality leaves something to be desired. [0]: https://github.com/openjdk/jmh
In I completed 100 Days of Java over 5 years and mapped the journey as a graph
And since benchmarking is hard is also has a helper to actually "waste" time. [1] The implementation [2] might give an idea that it is not always trivial to do nothing but still appear busy. Btw I found most of the jmh samples interesting. IMO a quite effective mix of example and documentation. (and I'm not sure there is even much other official documentation) [1] https://github.com/openjdk/jmh/blob/master/jmh-samples/src/m... [2] https://github.com/openjdk/jmh/blob/872b7203c294d90c17766d19...
In Show HN: Samchika – A Java Library for Fast, Multithreaded File Processing
For benchmarks it is generally recommended to use JMH [1] instead of coding your own warm-up, timing & GC profiling implementation. Playing around with a quick JMH set-up [2], there are a few new findings though: | Benchmark | Count | Preallocate | Time (ns/op) | Allocation (B/op) | Allocation (op) | |-----------+-------+-------------+--------------+-------------------+---------------------| | OnHeap | 10^6 | true | 6231838 | 16000020 | ~ 1 | | OffHeap | 10^6 | true | 6819142 | 54 | Should also be ~ 1 | | OnHeap | 10^6 | false | 9719988 | 33554598 | ~ 17 | | OffHeap | 10^6 | false | 19450448 | 773 | Should also be ~ 17 | 1. The difference between on/off-heap Python-like impl
Read the rest
ementation is less significant (~ 10%) provided that we preallocate things correctly. 2. The off-heap (MemorySegment) implementation slows down as the number of allocation increasing. EDIT: Profiling with JMH (using -prof async) shows that the off-heap implementation spent quite some time on jdk.internal.misc.Unsafe.getIntUnaligned in its resizeIfNeeded method, which should be the culprit here - Java array are guaranteed to be aligned (at least in HotSpot JVM), and aligned operations are much more efficient than unaligned ones, which should be able to explain the performance hit. --- 55482970432 ns (18.53%), 5548 samples [ 0] jdk.internal.misc.Unsafe.getIntUnaligned [ 1] jdk.internal.misc.ScopedMemoryAccess.getIntUnalignedInternal [ 2] jdk.internal.misc.ScopedMemoryAccess.getIntUnaligned [ 3] java.lang.invoke.VarHandleSegmentAsInts.get [ 4] java.lang.invoke.VarHandleGuards.guard_LJ_I [ 5] jdk.internal.foreign.AbstractMemorySegmentImpl.get [ 6] gc_less.python_like.IntHashtableOffHeap.resizeIfNeeded [ 7] gc_less.python_like.IntHashtableOffHeap.put [ 8] gc_less.benchmarks.OffHeapBenchmark.testPutOffHeap [1] https://github.com/openjdk/jmh [2] https://github.com/gudzpoz/gc_less/commit/17dcc3eb57b89f2642...
In Experimenting with GC-less (heap-less) Java

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.