{"id":21331574,"url":"https://github.com/lukechampine/fastxor","last_synced_at":"2025-07-12T10:30:59.304Z","repository":{"id":53589553,"uuid":"139909694","full_name":"lukechampine/fastxor","owner":"lukechampine","description":"The fastest way to xor bytes in Go","archived":false,"fork":false,"pushed_at":"2021-03-22T20:16:28.000Z","size":17,"stargazers_count":71,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-19T19:30:27.763Z","etag":null,"topics":["assembly","xor"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukechampine.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}},"created_at":"2018-07-05T23:17:45.000Z","updated_at":"2023-12-29T16:29:09.000Z","dependencies_parsed_at":"2022-09-26T18:10:49.906Z","dependency_job_id":null,"html_url":"https://github.com/lukechampine/fastxor","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/lukechampine%2Ffastxor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Ffastxor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Ffastxor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechampine%2Ffastxor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukechampine","download_url":"https://codeload.github.com/lukechampine/fastxor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225814912,"owners_count":17528295,"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":["assembly","xor"],"created_at":"2024-11-21T22:42:32.893Z","updated_at":"2024-11-21T22:42:33.436Z","avatar_url":"https://github.com/lukechampine.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"fastxor\n-----\n\n[![GoDoc](https://godoc.org/github.com/lukechampine/fastxor?status.svg)](https://godoc.org/github.com/lukechampine/fastxor)\n[![Go Report Card](http://goreportcard.com/badge/github.com/lukechampine/fastxor)](https://goreportcard.com/report/github.com/lukechampine/fastxor)\n\n```\ngo get github.com/lukechampine/fastxor\n```\n\nIs there a gaping hole in your heart that can only be filled by xor'ing byte\nstreams at 60GB/s? If so, you've come to the right place.\n\n`fastxor` is exactly what it sounds like: a package that xors bytes as fast\nas your CPU is capable of. For best results, use a CPU that supports a SIMD\ninstruction set like SSE or AVX. On other architectures,  performance is much\nless impressive, but still faster than a naive byte-wise loop.\n\nI wrote this package to try my hand at writing Go assembly, so please scrutinize\nmy code and let me know how I could make it faster or cleaner! \n\n\n# Benchmarks\n\n```\nAVX:\n\nBenchmarkBytes/16-4   \t200000000\t         6.20 ns/op\t 2579.65 MB/s\nBenchmarkBytes/1024-4 \t100000000\t        15.5 ns/op\t66089.39 MB/s\nBenchmarkBytes/65k-4  \t  2000000\t       974 ns/op\t67217.99 MB/s\n\nSSE:\n\nBenchmarkBytes/16-4   \t200000000\t         6.31 ns/op\t 2536.64 MB/s\nBenchmarkBytes/1024-4 \t 50000000\t        27.2 ns/op\t37609.69 MB/s\nBenchmarkBytes/65k-4  \t  1000000\t      2009 ns/op\t32619.21 MB/s\n\nWord-wise:\n\nBenchmarkBytes/16-4   \t200000000\t         7.37 ns/op\t 2170.17 MB/s\nBenchmarkBytes/1024-4 \t 20000000\t        89.4 ns/op\t11455.33 MB/s\nBenchmarkBytes/65k-4  \t   300000\t      4963 ns/op\t13203.25 MB/s\n\nByte-wise:\n\nBenchmarkBytes/16-4    \t100000000\t        12.7 ns/op\t 1263.77 MB/s\nBenchmarkBytes/1024-4  \t  2000000\t       610 ns/op\t 1677.18 MB/s\nBenchmarkBytes/65k-4   \t    50000\t     38906 ns/op\t 1684.45 MB/s\n```\n\nConclusions: `fastxor` is 2-40 times faster than a naive `for` loop. AVX is\nroughly twice as fast as SSE, which is unsurprising since it can operate on\ntwice as many bits per cycle. Lastly, for very small slices, the cost of the\nfunction call starts to outweigh the benefit of AVX/SSE (the Go compiler never\ninlines handwritten asm). If you need to xor exactly 16 bytes (common in block\nciphers), the specialized `Block` function is about 6 times faster than the\nmore generic `Bytes`:\n\n```\nBenchmarkBlock-4      \t2000000000\t        1.18 ns/op\t13546.30 MB/s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechampine%2Ffastxor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukechampine%2Ffastxor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechampine%2Ffastxor/lists"}