{"id":16620279,"url":"https://github.com/chrisgleissner/java-benchmarks","last_synced_at":"2025-10-26T12:02:24.745Z","repository":{"id":55422734,"uuid":"157289578","full_name":"chrisgleissner/java-benchmarks","owner":"chrisgleissner","description":"Java 21 Benchmarks using JMH","archived":false,"fork":false,"pushed_at":"2024-10-07T16:35:48.000Z","size":742,"stargazers_count":4,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-13T02:43:56.206Z","etag":null,"topics":["benchmark","collection","gradle","java","java21","jmh","parallel","performance","reflection","stream"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisgleissner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T23:05:56.000Z","updated_at":"2024-07-06T14:24:12.000Z","dependencies_parsed_at":"2024-04-28T09:41:31.303Z","dependency_job_id":"de7bf695-77f9-4f5e-a3ec-4218899c53b3","html_url":"https://github.com/chrisgleissner/java-benchmarks","commit_stats":null,"previous_names":["chrisgleissner/java-benchmarks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisgleissner%2Fjava-benchmarks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisgleissner%2Fjava-benchmarks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisgleissner%2Fjava-benchmarks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisgleissner%2Fjava-benchmarks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisgleissner","download_url":"https://codeload.github.com/chrisgleissner/java-benchmarks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238899911,"owners_count":19549401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","collection","gradle","java","java21","jmh","parallel","performance","reflection","stream"],"created_at":"2024-10-12T02:43:53.935Z","updated_at":"2025-10-26T12:02:24.673Z","avatar_url":"https://github.com/chrisgleissner.png","language":"Java","readme":"# Java 21 JMH Benchmarks\n\n[![build](https://github.com/chrisgleissner/java-benchmarks/actions/workflows/build.yaml/badge.svg)](https://github.com/chrisgleissner/java-benchmarks/actions/workflows/build.yaml)\n[![benchmark](https://github.com/chrisgleissner/java-benchmarks/actions/workflows/benchmark.yaml/badge.svg)](https://github.com/chrisgleissner/java-benchmarks/actions/workflows/benchmark.yaml)\n\nJava 21 [JMH](https://github.com/openjdk/jmh) benchmarks for field access, counters, collections, sequential and\nparallel streams, etc.\n\n## Results\n\nView [result charts](https://jmh.morethan.io/?source=https://raw.githubusercontent.com/chrisgleissner/java-benchmarks/main/jmh-result-all.json)\nvia [JMH Visualizer](https://jmh.morethan.io).\n\nAlternatively, download the [result JSON](./jmh-result-all.json).\n\n### Test Environment\n\nThe following test environment was used to create the results above.\n\n#### Hardware\n\n- CPU: Intel Core i7-6700K at 4.00GHz with 4 cores (8 threads)\n- Motherboard: Asus Z170-A\n- RAM: 32 GiB DDR4 (2 x Corsair 16 GiB, 2133 MT/s)\n- Virtualization: None; bare metal desktop\n\n#### Software\n\n- Java: Amazon Corretto 21.0.3.9.1\n- OS: Ubuntu 22.04.4 LTS\n- Kernel: 5.15.86-051586-generic\n- JVM args: `-Xms4g -Xmx4g -Xlog:gc=info:stdout`\n\n## Usage\n\n```shell\n./benchmark.sh -h\n\nUsage: ./benchmark.sh [OPTIONS]\nOptions:\n  -i, --includes \u003cREGEX\u003e                Regular expression pattern of benchmark(s). Default is '.*'.\n  -o, --operations-per-invocation \u003cINT\u003e Operations per invocation. Default is 10.\n  -t, --time-on-iteration \u003cTIME\u003e        Time per measurement iteration. Default is '1s'.\n  -j, --jmh-timeout \u003cTIME\u003e              Timeout for benchmark iteration. Default is '10m'.\n  -w, --warmup \u003cTIME\u003e                   Warmup time per iteration. Default is '1s'.\n  -b, --warmup-batch-size \u003cINT\u003e         Warmup batch size. Default is 10.\n  -wi, --warmup-iterations \u003cINT\u003e        Number of warmup iterations. Default is 5.\n  -it, --iterations \u003cINT\u003e               Number of measurement iterations. Default is 10.\n  -bch, --batch-size \u003cINT\u003e              Batch size. Default is 1.\n  -f, --fork \u003cINT\u003e                      Number of benchmark forks. Default is 1.\n  -fe, --fail-on-error \u003ctrue/false\u003e     Fail JMH on error? Default is false.\n  -gc, --force-gc \u003ctrue/false\u003e          Force GC between iterations? Default is false.\n  -h, --help                            Show this help message.\n```\n\n## Run\n\nRun all benchmarks:\n\n```shell\n./benchmark.sh\n```\n\nRun specific benchmark(s):\n\n```shell\n./benchmark.sh --includes \u003cREGEX\u003e\n```\n\nExamples:\n\n```shell\n./benchmark.sh --includes Time.*\n./benchmark.sh -i Time\n./benchmark.sh -i nano\n```\n\nAfter completion, you find the results in `./jmh-result-all.json`.\n\n## Details\n\n\u003e [!NOTE]\n\u003e Unless stated otherwise, benchmark throughput measurements are for a single operation, e.g. a single addition to a\n\u003e collection\n\u003e or a single iterator advancement.\n\n### Counter\n\nAtomicInteger vs [MutableInt](https://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html) vs int,\nsame for the corresponding long types.\n\n### Getter / Setter\n\nComparing various ways of getting and setting object fields.\n\nOrdered by performance from top to bottom, the ranking is:\n\n1. Direct call\n1. [LambdaMetaFactory](https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/LambdaMetafactory.html) - almost as\n   fast as direct, but requires at least a private accessor method\n1. Reflection - ca. 30% of the direct performance\n1. MethodHandle and VarHandle - ca. 20% of the direct performance\n\n### Collection\n\n#### ArrayAdd / CollectionAdd\n\nCompares adding elements to int/Integer/long/Long arrays as well as empty collections and maps.\n\n#### CollectionIterate\n\nIterating over all elements of pre-populated collections and maps.\n\n#### ConCollection\n\nConcurrent get (10 threads), add (2 threads) and remove (1 thread) of Integer elements for a number of thread-safe\ncollection classes. The non thread-safe ArrayList class is included in this benchmark and gets protected by wrapping it\nvia `Collections.synchronizedList()`.\n\nEach data structure gets populated before he benchmark. Access occurs for the head of the data structure (where the\nconcept of head is supported), otherwise (such as in the instance of maps) by key.\n\n#### Stream\n\nCompares streaming over primitive and wrapper classes compared with using a for loop. The stream collects filtered\nelements into a target data structure. This benchmarks also compares single threaded with parallel streaming over data\nstructures of varying length.\n\n\u003e [!NOTE]\n\u003e In contrast to the other benchmarks, the measurements here are for processing the entire stream. The benchmark is run\n\u003e repeatedly\n\u003e for increasing stream lengths, from 1 to 10 million in \"one order of magnitude\" increments. Thus, as the stream length\n\u003e increases, the measured\n\u003e throughput decreases.\n\n### ObjectCache\n\nCompares the use of ints, custom int wrappers instantiation, and a custom int wrapper cache.\n\n### Time\n\nCompares `System.currentTimeMillis`, `System.nanoTime`, and various `java.time` classes.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisgleissner%2Fjava-benchmarks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisgleissner%2Fjava-benchmarks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisgleissner%2Fjava-benchmarks/lists"}