#minecraft #performance #minimum #maximum #memory #varint #var-long

mc-varint

Minecraft的VarInt和VarLong实现,在Rust中提供最小内存使用和最大性能

2个版本

使用旧Rust 2015

0.1.1 2018年7月9日
0.1.0 2018年7月8日

#17 in #minimum

Download history 27/week @ 2024-04-07 22/week @ 2024-04-14 18/week @ 2024-04-21 25/week @ 2024-04-28 28/week @ 2024-05-05 19/week @ 2024-05-12 22/week @ 2024-05-19 12/week @ 2024-05-26 17/week @ 2024-06-02 9/week @ 2024-06-09 22/week @ 2024-06-16 14/week @ 2024-06-23 1/week @ 2024-06-30 4/week @ 2024-07-07 41/week @ 2024-07-14 42/week @ 2024-07-21

89 每月下载量
用于 elytra-ping

WTFPL 许可协议

11KB
105

mc-varint

Minecraft VarInt和VarLong实现,在Rust中提供最小内存使用和最大性能。

Crates.io WTFPL licensed

示例

从Read中读取VarInt

extern crate mc_varint;
use mc_varint::{VarInt, VarIntRead};
use std::io::Cursor;
fn main() {
    // firstly we create a Cursor
    let mut cur = Cursor::new(vec![0xff, 0xff, 0xff, 0xff, 0x07]);
    // secondly we read from it
    let var_int = cur.read_var_int().unwrap();
    // the value of var_int is 2147483647
    assert_eq!(var_int, VarInt::from(2147483647));
}

将VarInt写入Write

extern crate mc_varint;
use mc_varint::{VarInt, VarIntWrite};
use std::io::Cursor;
fn main() {
    // firstly we create a Cursor and a VarInt
    let mut cur = Cursor::new(Vec::with_capacity(5));
    let var_int = VarInt::from(2147483647);
    // secondly we write the VarInt to the Cursor
    cur.write_var_int(var_int).unwrap();
    // now the var_int is written to cur.
    assert_eq!(cur.into_inner(), vec![0xff, 0xff, 0xff, 0xff, 0x07]);
}

性能

平台:3.4GHz Intel Core i5

running 6 tests
test var_int_convert  ... bench:           7 ns/iter (+/- 0)
test var_int_read     ... bench:          33 ns/iter (+/- 29)
test var_int_write    ... bench:          88 ns/iter (+/- 9)
test var_long_convert ... bench:          10 ns/iter (+/- 1)
test var_long_read    ... bench:          56 ns/iter (+/- 5)
test var_long_write   ... bench:         180 ns/iter (+/- 31)

test result: ok. 0 passed; 0 failed; 0 ignored; 6 measured; 0 filtered out

无运行时依赖