Token Counter
v0.1.0Added Sep 26, 2026Sample dataCounts BPE tokens for OpenAI-compatible encodings (cl100k_base, o200k_base) without building the token list.
cargo install kura-rs
kura add token-counterCopies 3 source files into your project. You own the code from then on.
If another tool already installs a kura command, run cargo install kura-rs --bin kura-rs and use kura-rs add instead.
use crate::parts::token_counter::{Encoding, count};
let n = count(Encoding::O200kBase, &prompt);
assert!(n <= 128_000, "prompt too long: {n} tokens");Verification
Sample dataChecked against tiktoken 0.9.0 (Python) using differential testing: the same inputs go to both implementations and the outputs are compared.
These numbers are placeholders. They have not been measured yet and must not be read as real results. This part is marked "sample": true in its registry file.
Benchmarks
Sample datakura-rs (Rust) against tiktoken across input sizes. Faster from about 1,285 inputs, up to 1.7× faster.
These numbers are placeholders. They have not been measured yet and must not be read as real results. This part is marked "sample": true in its registry file.
Show data table
| Input size | kura-rs (Rust) | tiktoken | Speedup |
|---|---|---|---|
| 100 | 0.05 ms | 0.03 ms | 1.7× slower |
| 1,000 | 0.31 ms | 0.3 ms | 1.0× slower |
| 10,000 | 2.6 ms | 3.4 ms | 1.3× |
| 100,000 | 24 ms | 36 ms | 1.5× |
| 1,000,000 | 235 ms | 390 ms | 1.7× |
Files
- parts/token_counter/mod.rs
- parts/token_counter/bpe.rs
- parts/token_counter/ranks.rs