[][src]Crate shortscale

Converts numbers into English words.

The short scale, has different words for each power of 1000.

This library expresses numbers from zero to thousands, millions, billions, trillions, and quadrillions, up to 999_999_999_999_999_999.

Sample benchmarks

cargo bench on MacOS Catalina 2.6 GHz Intel Core i7

shortscale                250.56 ns
shortscale_vec_push       356.90 ns
shortscale_vec_concat   4.686 us
shortscale_string_join  5.395 us

cargo bench on GitHub Actions Ubuntu 18.04

shortscale                271.79 ns
shortscale_vec_push       258.43 ns
shortscale_vec_concat   1.4559 us
shortscale_string_join  1.6146 us

github | crates.io

Copyright 2021, Jürgen Leschner - github.com/jldec - MIT license

Functions

shortscale

Returns String with words given an unsigned integer.
Builder implementation mutates pre-allocated String by calling push_str().

shortscale_string_join

Reimplementation of shortscale_vec_concat
Composition pushing Strings returned from functions.
This is even slower than concatenating Vecs.

shortscale_vec_concat

First Rust implementation (ever for me)
Modeled after javascript version
Functional composition by allocating and concatenating Vecs.
This is ~20x slower than the String builder and ~5x slower than JavaScript.

shortscale_vec_push

Reimplementation of shortscale.
Uses Vec builder instead of String builder.
On MacOS this implementation is ~60% slower than building a String directly.
On GitHub Actions Ubuntu it is slightly faster.