{"id":16572818,"url":"https://github.com/lemire/despacer","last_synced_at":"2025-04-13T10:44:26.668Z","repository":{"id":48779942,"uuid":"79483907","full_name":"lemire/despacer","owner":"lemire","description":"C library to remove white space from strings as fast as possible","archived":false,"fork":false,"pushed_at":"2024-09-05T23:57:39.000Z","size":1307,"stargazers_count":152,"open_issues_count":6,"forks_count":15,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-27T02:09:49.734Z","etag":null,"topics":["ascii","avx","bytes","simd","simd-programming","sse","ssse3"],"latest_commit_sha":null,"homepage":"","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":"2017-01-19T18:50:11.000Z","updated_at":"2025-01-13T16:50:21.000Z","dependencies_parsed_at":"2024-10-27T11:26:17.611Z","dependency_job_id":"b70deb73-82b7-4f31-86c4-ba80c44634c0","html_url":"https://github.com/lemire/despacer","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%2Fdespacer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fdespacer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fdespacer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fdespacer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemire","download_url":"https://codeload.github.com/lemire/despacer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248702145,"owners_count":21148114,"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":["ascii","avx","bytes","simd","simd-programming","sse","ssse3"],"created_at":"2024-10-11T21:28:38.784Z","updated_at":"2025-04-13T10:44:26.650Z","avatar_url":"https://github.com/lemire.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# despacer\n[![VS17-CI](https://github.com/lemire/despacer/actions/workflows/vs.yml/badge.svg)](https://github.com/lemire/despacer/actions/workflows/vs.yml)\n[![Ubuntu 22.04 CI (GCC 11)](https://github.com/lemire/despacer/actions/workflows/ubuntu22.yml/badge.svg)](https://github.com/lemire/despacer/actions/workflows/ubuntu22.yml)\n\nFast C library to remove white space from strings (also called \"strip white space\").\n\nWe want to remove the space (' ') and the line feeds characters ('\\n', '\\r') from a string\nas fast as possible. To avoid unnecessary allocations, we wish to do the processing in-place.\n\nLet us consider any array of bytes representing a string in one of these encodings:\n* UTF-8\n* ASCII\n* Any of the 8-bit ASCII supersets such as Latin1\n\nHow fast can we go?\n\nBlog post:\nhttp://lemire.me/blog/2017/01/20/how-quickly-can-you-remove-spaces-from-a-string/\n\n\n### Build:\n\nMake sure you have a recent cmake (3.15 or better):\n\n```\ncmake -B build -DCMAKE_BUILD_TYPE=Release \u0026\u0026 cmake --build build\n```\n\nYou may run tests by entering the  `build` repository and typing `ctest`.\n\nVisual Studio users may further want to specify the build configuration (Release/Debug).\n\nUsing the above,cmake builds the library, tests and benchmarking tool. The benchmark tool\nrequires GCC/clang under x64 (it is otherwise omitted).\n\n\n\n### D Bindings\n\nAdd this repository as a submodule to your project.\n\n```shell\ngit submodule add https://github.com/lemire/despacer.git despacer\ngit submodule update --init --recursive\n```\n\nThen, add the following to your `dub.json` file.\n\n```json\n\"dependencies\": {\n    \"despacer\": {\n        \"path\": \"./despacer\"\n    }\n}\n```\n\n### Benchmarks\n\nNote that clang seems to give better results than gcc.\n\nPossible results...\n\n```\n$ make benchmark\npointer alignment = 16 bytes\nmemcpy(tmpbuffer,buffer,N):  0.111328 cycles / ops\ncountspaces(buffer, N):  3.687500 cycles / ops\ndespace(buffer, N):  5.337891 cycles / ops\nfaster_despace(buffer, N):  1.689453 cycles / ops\ndespace64(buffer, N):  2.429688 cycles / ops\ndespace_to(buffer, N, tmpbuffer):  5.585938 cycles / ops\navx2_countspaces(buffer, N):  0.367188 cycles / ops\navx2_despace(buffer, N):  3.990234 cycles / ops\navx2_despace_branchless(buffer, N):  0.593750 cycles / ops\navx2_despace_branchless_u2(buffer, N):  0.535156 cycles / ops\nsse4_despace(buffer, N):  0.734375 cycles / ops\nsse4_despace_branchless(buffer, N):  0.384766 cycles / ops\nsse4_despace_branchless_u2(buffer, N):  0.380859 cycles / ops\nsse4_despace_branchless_u4(buffer, N):  0.351562 cycles / ops\nsse4_despace_trail(buffer, N):  1.142578 cycles / ops\nsse42_despace_branchless(buffer, N):  0.763672 cycles / ops\nsse42_despace_branchless_lookup(buffer, N):  0.673828 cycles / ops\nsse42_despace_to(buffer, N,tmpbuffer):  1.703125 cycles / ops\n```\n\nThis indicates how many cycles are used to despace one byte.\n\n### Related work\n\n- a related problem on ARM processors with iOS app https://github.com/DerekScottLedbetter/space-pruner\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fdespacer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemire%2Fdespacer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fdespacer/lists"}