{"id":17004347,"url":"https://github.com/msdousti/jmh-benchmark","last_synced_at":"2026-02-14T19:03:21.241Z","repository":{"id":47772100,"uuid":"219079338","full_name":"msdousti/jmh-benchmark","owner":"msdousti","description":"A simple Java project to benchmark the speed of JDK AES vs BouncyCastle AES.","archived":false,"fork":false,"pushed_at":"2025-01-10T16:13:52.000Z","size":13,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-28T22:03:47.330Z","etag":null,"topics":["aes","benchmark","bouncycastle","ctr","jdk","jmh"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msdousti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2019-11-01T23:51:01.000Z","updated_at":"2025-01-10T16:13:56.000Z","dependencies_parsed_at":"2025-08-28T17:02:14.565Z","dependency_job_id":null,"html_url":"https://github.com/msdousti/jmh-benchmark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/msdousti/jmh-benchmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msdousti%2Fjmh-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msdousti%2Fjmh-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msdousti%2Fjmh-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msdousti%2Fjmh-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msdousti","download_url":"https://codeload.github.com/msdousti/jmh-benchmark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msdousti%2Fjmh-benchmark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29452594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["aes","benchmark","bouncycastle","ctr","jdk","jmh"],"created_at":"2024-10-14T04:43:24.827Z","updated_at":"2026-02-14T19:03:21.226Z","avatar_url":"https://github.com/msdousti.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JDK vs. BC Benchmark\n\nA simple Java project to benchmark the speed of JDK AES vs BouncyCastle AES (both in [CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR))).\n\nIn my experience, JDK-11 performs extremely faster than BouncyCastle, since the former uses [AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set) while the latter is purely Java based. (Reference: https://github.com/bcgit/bc-java/issues/221).\n\nSnippets of JMH output on my laptop:\n\n* JDK-11 (version 11.0.5)\n```\nBenchmark                  Mode  Cnt     Score    Error  Units\nJdkVsBcBenchmark.aes_jdk  thrpt   30  3395.140 ± 42.616  ops/s\n```\n\n* BouncyCastle\n```\nBenchmark                 Mode  Cnt    Score   Error  Units\nJdkVsBcBenchmark.aes_bc  thrpt   30  132.869 ± 0.842  ops/s\n```\n\nThe results show that JDK-11 implementation of AES is over 25 times faster than BouncyCastle.\n\n* Results for JDK-8 (version 1.8.0_231)\n```\nBenchmark                  Mode  Cnt    Score   Error  Units\nJdkVsBcBenchmark.aes_jdk  thrpt   30  346.398 ± 1.313  ops/s\n```\n\nCompared to JDK-11, it is very slow (though still three times faster than BouncyCastle). Two posts on StackOverflow ([link-1](https://stackoverflow.com/q/25505870/459391) and [link-2](https://stackoverflow.com/q/23058309/459391)) discuss whether JDK-8 exploits AES-NI instruction set by default (apparently, it does!). I also explicitly tested the program with the corresponding JVM flags (`-XX:+UseAES -XX:+UseAESIntrinsics`), but to no avail: The result was the same.\n\n## Comparison with OpenSSL\nJDK-11 performs ~ 3395 operations per second, where each operation corresponds to encryption 1 MB of data using AES-CTR. That is, encryption speed is about 3.3 GB/s. Comparison with OpenSSL is indeed insightful:\n\n```\nopenssl speed -evp aes-128-ctr\n\nDoing aes-128-ctr for 3s on 16 size blocks: 181395748 aes-128-ctr's in 2.98s\nDoing aes-128-ctr for 3s on 64 size blocks: 100434456 aes-128-ctr's in 3.00s\nDoing aes-128-ctr for 3s on 256 size blocks: 51261409 aes-128-ctr's in 3.00s\nDoing aes-128-ctr for 3s on 1024 size blocks: 16451696 aes-128-ctr's in 3.00s\nDoing aes-128-ctr for 3s on 8192 size blocks: 2242294 aes-128-ctr's in 3.00s\nOpenSSL 1.0.2p  14 Aug 2018\nbuilt on: reproducible build, date unspecified\noptions:bn(64,64) rc4(16x,int) des(idx,cisc,2,long) aes(partial) idea(int) blowfish(idx)\ncompiler: gcc -I. -I.. -I../include -I/mingw64/include -D_WINDLL -DOPENSSL_PIC -DZLIB_SHARED -DZLIB -DOPENSSL_THREADS -D_MT -DDSO_WIN32 -DL_ENDIAN -O3 -g -Wall -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM\nThe 'numbers' are in 1000s of bytes per second processed.\ntype             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes\naes-128-ctr     972509.14k  2142601.73k  4374306.90k  5615512.23k  6122957.48k\n```\n\nAs the output indicates, OpenSSL runs a series of benchmarks on various input sizes, from 16 bytes to 8192 bytes. In order to compare this with our Java code, we need to adapt the input size (1 MB) in the code. Better yet, we can use [OpenSSL 1.1.1, which supports `-bytes` argument](https://www.openssl.org/docs/man1.1.1/man1/openssl-speed.html):\n\n```\nopenssl.exe speed -evp aes-128-ctr -bytes 1073741824\n\nDoing aes-128-ctr for 3s on 1073741824 size blocks: 17 aes-128-ctr's in 3.08s\nOpenSSL 1.1.1c  28 May 2019\nbuilt on: Wed May 29 04:30:04 2019 UTC\noptions:bn(64,64) rc4(16x,int) des(long) aes(partial) idea(int) blowfish(ptr)\ncompiler: cl /Z7 /Fdossl_static.pdb /Gs0 /GF /Gy /MD /W3 /wd4090 /nologo /O2 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -D_USING_V110_SDK71_ -D_WINSOCK_DEPRECATED_NO_WARNINGS\nThe 'numbers' are in 1000s of bytes per second processed.\ntype        1073741824 bytes\naes-128-ctr    5930107.13k\n```\n\nEvidently, OpenSSL is almost twice as fast as JDK-11.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsdousti%2Fjmh-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsdousti%2Fjmh-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsdousti%2Fjmh-benchmark/lists"}