{"id":16572802,"url":"https://github.com/lemire/fast_division","last_synced_at":"2025-03-21T12:31:14.296Z","repository":{"id":66054855,"uuid":"362216688","full_name":"lemire/fast_division","owner":"lemire","description":"Simple C++ code to benchmark fast division algorithms","archived":false,"fork":false,"pushed_at":"2021-05-06T16:19:20.000Z","size":25,"stargazers_count":47,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-18T01:11:21.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/lemire.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}},"created_at":"2021-04-27T18:43:16.000Z","updated_at":"2024-10-14T16:05:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"b69d4594-05cd-4b94-9fb6-2436143305be","html_url":"https://github.com/lemire/fast_division","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Ffast_division","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Ffast_division/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Ffast_division/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Ffast_division/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemire","download_url":"https://codeload.github.com/lemire/fast_division/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244799318,"owners_count":20512233,"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":[],"created_at":"2024-10-11T21:28:36.687Z","updated_at":"2025-03-21T12:31:14.287Z","avatar_url":"https://github.com/lemire.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fast_division\nSimple C++ code to benchmark fast division algorithms relying on constant divisors.\n\n\nThe code is a companion to the paper [Integer Division by Constants: Optimal Bounds](https://arxiv.org/abs/2012.12369) in the sense that it illustrates the results. It should be viewed as a research artefact.\n\n\n## Usage\n\nThe code is made of a single header file (`fast_division.h`).\n\nCopy `fast_division.h` in your C++ project. You can then use it as follows.\n\n```C++\n#include \"fast_division/fast_division.h\"\n\n// for any compile-time constant 'divisor' we have:\nassert(fast_division::divide32\u003cdivisor\u003e::quotient(n) == n / divisor);\nassert(fast_division::divide32\u003cdivisor\u003e::remainder(n) == n % divisor)\nassert(fast_division::divide32\u003cdivisor\u003e::is_divisible(n) == (n % divisor == 0));\n```\n\n## Benchmarks\n\n```\n❯ cmake -B build \u0026\u0026 cmake --build build\n./build/benchmark/benchmark\n```\n\nOn an Apple M1 processor with clang 12, we get:\n\n```\n❯ ./build/benchmark/benchmark\ndivisor = 19\nstd division                            :     0.91 ns/ops (+/- 3.8 %)\nfast division                           :     0.31 ns/ops (+/- 1.0 %)\nstd remainder                           :     0.76 ns/ops (+/- 0.7 %)\nfast remainder                          :     0.62 ns/ops (+/- 4.7 %)\ndivisor = 123456\nstd division                            :     0.84 ns/ops (+/- 0.7 %)\nfast division                           :     0.31 ns/ops (+/- 1.1 %)\nstd remainder                           :     0.62 ns/ops (+/- 0.6 %)\nfast remainder                          :     0.31 ns/ops (+/- 16.0 %)\ndivisor = 4096\nstd division                            :     0.58 ns/ops (+/- 1.8 %)\nfast division                           :     0.58 ns/ops (+/- 1.8 %)\nstd remainder                           :     0.72 ns/ops (+/- 0.7 %)\nfast remainder                          :     0.72 ns/ops (+/- 0.6 %)\n```\n\nOn an AMD Zen 2 processor with GCC 10, we get:\n\n```\n$ ./build/benchmark/benchmark\ndivisor = 19\nstd division                            :     0.87 ns/ops (+/- 1.0 %)\nfast division                           :     0.44 ns/ops (+/- 3.4 %)\nstd remainder                           :     1.15 ns/ops (+/- 0.1 %)\nfast remainder                          :     0.82 ns/ops (+/- 0.3 %)\ndivisor = 123456\nstd division                            :     0.59 ns/ops (+/- 2.9 %)\nfast division                           :     0.43 ns/ops (+/- 4.3 %)\nstd remainder                           :     0.76 ns/ops (+/- 10.5 %)\nfast remainder                          :     0.64 ns/ops (+/- 1.0 %)\ndivisor = 4096\nstd division                            :     0.29 ns/ops (+/- 0.4 %)\nfast division                           :     0.29 ns/ops (+/- 0.3 %)\nstd remainder                           :     0.29 ns/ops (+/- 0.4 %)\nfast remainder                          :     0.29 ns/ops (+/- 0.4 %)\n```\n\nResults will vary depending on your compiler and processor. They also depend on the divisor.\n\nThe benchmark measures throughput, not latency.\n\n## Further reading and code\n\n\nFor a practical library with performance claims, see [fastmod](https://github.com/lemire/fastmod) and the manuscript:\n\n- Daniel Lemire, Owen Kaser, Nathan Kurz, [Faster Remainder by Direct Computation: Applications to Compilers and Software Libraries](https://arxiv.org/abs/1902.01961), Software: Practice and Experience 49 (6), 2019\n\n## Limitations and requirements\n\n- We currently assume that the divisor is a compile-time constant. Extending to runtime constants is possible.\n- We assume a recent compiler (C++11 or better). If you are interested in supporting legacy compilers, pull requests are invited.\n- Currently, only 32-bit unsigned integers are supported. Adding other data types is merely a matter of extra programming effort.\n- We assume a GCC-like compiler like GCC/LLVM clang. Pull requests to support Visual Studio and other compilers are invited.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Ffast_division","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemire%2Ffast_division","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Ffast_division/lists"}