#ulid #github #rewrites #closures #timestamp #com-suyash-ulid #unmarshal

ulid-rs

将 https://github.com/suyash/ulid 从 C++ 转换为 Rust

1 个不稳定版本

0.1.0 2020年7月10日

#213 in 性能分析


ulid-generator-rs 使用

MIT/Apache

19KB
238

ulid-rs

Continuous Integration

https://github.com/suyash/ulid 从 C++ 转换为 Rust

为 Ulid 创建提供一个单一接口

Ulid::new(u64, Fn() -> u8)

取传递的时间戳的最后 48 位,并对随机值调用传递的闭包 10 次。

代替显式的 MarshalBinary 和 UnmarshalBinary,实现了 Into<[u8; 16]>Into<&[u8]>Into<Vec<u8>>From<[u8; 16]>TryFrom<&[u8]>

还实现了与 marshal 相结合的返回 26 个 UTF-8 单词的 TryInto<String>TryInto<&str>ToString

除了与unmarshal一起工作的AsRef<[u8]>之外,还实现了TryFrom<String>TryFrom<&str>

大多数基准测试的性能与C++相似,部分有所提升。基准测试使用GitHub Actions和criterion运行。

基准测试

C++测试结果:[https://github.com/suyash/ulid#benchmarks](https://github.com/suyash/ulid#benchmarks)

稳定版本的测试结果([https://github.com/suyash/ulid-rs/runs/858815380](https://github.com/suyash/ulid-rs/runs/858815380))

Benchmarking new
Benchmarking new: Warming up for 3.0000 s
Benchmarking new: Collecting 100 samples in estimated 5.0000 s (426M iterations)
Benchmarking new: Analyzing
new                     time:   [11.716 ns 11.719 ns 11.722 ns]
Found 10 outliers among 100 measurements (10.00%)
  2 (2.00%) low severe
  4 (4.00%) high mild
  4 (4.00%) high severe

Benchmarking new_systemtime_now
Benchmarking new_systemtime_now: Warming up for 3.0000 s
Benchmarking new_systemtime_now: Collecting 100 samples in estimated 5.0002 s (97M iterations)
Benchmarking new_systemtime_now: Analyzing
new_systemtime_now      time:   [51.380 ns 51.389 ns 51.400 ns]
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) low mild
  1 (1.00%) high severe

Benchmarking new_utc_now
Benchmarking new_utc_now: Warming up for 3.0000 s
Benchmarking new_utc_now: Collecting 100 samples in estimated 5.0001 s (85M iterations)
Benchmarking new_utc_now: Analyzing
new_utc_now             time:   [58.817 ns 58.842 ns 58.867 ns]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe

Benchmarking new_rand_random
Benchmarking new_rand_random: Warming up for 3.0000 s
Benchmarking new_rand_random: Collecting 100 samples in estimated 5.0002 s (91M iterations)
Benchmarking new_rand_random: Analyzing
new_rand_random         time:   [54.703 ns 54.708 ns 54.713 ns]
Found 8 outliers among 100 measurements (8.00%)
  4 (4.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe

Benchmarking new_systemtime_now_rand_random
Benchmarking new_systemtime_now_rand_random: Warming up for 3.0000 s
Benchmarking new_systemtime_now_rand_random: Collecting 100 samples in estimated 5.0003 s (56M iterations)
Benchmarking new_systemtime_now_rand_random: Analyzing
new_systemtime_now_rand_random
                        time:   [89.519 ns 89.544 ns 89.579 ns]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

Benchmarking new_utc_now_rand_random
Benchmarking new_utc_now_rand_random: Warming up for 3.0000 s
Benchmarking new_utc_now_rand_random: Collecting 100 samples in estimated 5.0002 s (50M iterations)
Benchmarking new_utc_now_rand_random: Analyzing
new_utc_now_rand_random time:   [99.193 ns 99.205 ns 99.219 ns]
Found 7 outliers among 100 measurements (7.00%)
  2 (2.00%) low severe
  1 (1.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe

Benchmarking marshal
Benchmarking marshal: Warming up for 3.0000 s
Benchmarking marshal: Collecting 100 samples in estimated 5.0001 s (237M iterations)
Benchmarking marshal: Analyzing
marshal                 time:   [22.176 ns 22.179 ns 22.183 ns]
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe

Benchmarking marshal_to_string
Benchmarking marshal_to_string: Warming up for 3.0000 s
Benchmarking marshal_to_string: Collecting 100 samples in estimated 5.0002 s (108M iterations)
Benchmarking marshal_to_string: Analyzing
marshal_to_string       time:   [46.545 ns 46.575 ns 46.612 ns]
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) low mild
  3 (3.00%) high mild
  1 (1.00%) high severe

Benchmarking unmarshal
Benchmarking unmarshal: Warming up for 3.0000 s
Benchmarking unmarshal: Collecting 100 samples in estimated 5.0000 s (65M iterations)
Benchmarking unmarshal: Analyzing
unmarshal               time:   [77.037 ns 77.123 ns 77.214 ns]

Benchmarking timestamp
Benchmarking timestamp: Warming up for 3.0000 s
Benchmarking timestamp: Collecting 100 samples in estimated 5.0000 s (2.5B iterations)
Benchmarking timestamp: Analyzing
timestamp               time:   [2.0092 ns 2.0094 ns 2.0097 ns]
Found 10 outliers among 100 measurements (10.00%)
  2 (2.00%) low mild
  5 (5.00%) high mild
  3 (3.00%) high severe

许可证

ulid-rs在MIT许可证和Apache许可证(版本2.0)的条款下分发。

有关详细信息,请参阅LICENSE-APACHELICENSE-MIT

依赖关系

~305–770KB
~18K SLoC