• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

benches/H03-May-2022-8474

ci/H03-May-2022-168

src/H03-May-2022-784559

tests/H03-May-2022-9680

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Dec-202074 65

.gitignoreH A D19-Nov-202018 32

Cargo.tomlH A D01-Dec-20201.4 KiB5446

Cargo.toml.orig-cargoH A D01-Dec-2020899 3629

LICENSE.Apache2H A D19-Nov-202011.1 KiB202169

LICENSE.MITH A D19-Nov-20201 KiB2016

README.mdH A D19-Nov-20202.8 KiB7653

README.md

1# bytecount
2
3Counting bytes really fast
4
5[![Build Status](https://travis-ci.org/llogiq/bytecount.svg?branch=master)](https://travis-ci.org/llogiq/bytecount)
6[![Windows build status](https://ci.appveyor.com/api/projects/status/github/llogiq/bytecount?svg=true)](https://ci.appveyor.com/project/llogiq/bytecount)
7[![Current Version](http://meritbadge.herokuapp.com/bytecount)](https://crates.io/crates/bytecount)
8[![License: Apache 2.0/MIT](https://img.shields.io/crates/l/bytecount.svg)](#license)
9
10This uses the "hyperscreamingcount" algorithm by Joshua Landau to count bytes faster than anything else.
11The [newlinebench](https://github.com/llogiq/newlinebench) repository has further benchmarks for old versions of this repository.
12
13To use bytecount in your crate, if you have [cargo-edit](https://github.com/killercup/cargo-edit), just type
14`cargo add bytecount` in a terminal with the crate root as the current path. Otherwise you can manually edit your
15`Cargo.toml` to add `bytecount = 0.5.1` to your `[dependencies]` section.
16
17In your crate root (`lib.rs` or `main.rs`, depending on if you are writing a
18library or application), add `extern crate bytecount;`. Now you can simply use
19`bytecount::count` as follows:
20
21```Rust
22extern crate bytecount;
23
24fn main() {
25    let mytext = "some potentially large text, perhaps read from disk?";
26    let spaces = bytecount::count(mytext.as_bytes(), b' ');
27    ..
28}
29```
30
31bytecount supports two features to make use of modern CPU's features to speed up counting considerably. To allow your
32users to use them, add the following to your `Cargo.toml`:
33
34```
35[features]
36runtime-dispatch-simd = ["bytecount/runtime-dispatch-simd"]
37generic-simd = ["bytecount/generic-simd"]
38```
39
40The first, `runtime-dispatch-simd`, enables detection of SIMD capabilities at runtime, which allows using the SSE2 and
41AVX2 codepaths, but cannot be used with `no_std`.
42
43Your users can then compile with runtime dispatch using:
44
45```
46cargo build --release --features runtime-dispatch-simd
47```
48
49The second, `generic-simd`, uses `packed_simd` to provide a fast
50architecture-agnostic SIMD codepath, but requires running on nightly.
51
52Your users can compile with this codepath using:
53
54```
55cargo build --release --features generic-simd
56```
57
58Building for a more specific architecture will also improve performance.
59You can do this with
60
61```
62RUSTFLAGS="-C target-cpu=native" cargo build --release
63```
64
65The scalar algorithm is explained in depth [here](https://llogiq.github.io/2016/09/27/count.html).
66
67**Note: Versions until 0.4.0 worked with Rust as of 1.20.0. Version 0.5.0 until 0.6.0 requires Rust 1.26 or later,
68and at least 1.27.2 to use SIMD. Versions from 0.6.0 require Rust 1.32.0 or later.**
69
70## License
71
72Licensed under either of at your discretion:
73
74- [Apache 2.0](LICENSE.Apache2)
75- [MIT](LICENSE.MIT)
76