diff --git a/.vscode/settings.json b/.vscode/settings.json index d8da082..f837141 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,47 @@ { - "rust-analyzer.linkedProjects": [ - "crates/shen-nbt1/Cargo.toml", - "crates/shen-nbt2/Cargo.toml", - "crates/shen-nbt3/Cargo.toml", - "crates/shen-nbt4/Cargo.toml", - "crates/nbt-test/Cargo.toml", - ] + "files.associations": { + "*.html": "html", + "__bit_reference": "cpp", + "__config": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "execution": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "locale": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ratio": "cpp", + "span": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp", + "algorithm": "cpp" + } } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3ed5081 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[workspace] +members = [ + "nbt-test", + # "shen-nbt1", # EOL! + "shen-nbt2", + "shen-nbt3", + "shen-nbt4", + "shen-nbt5", +] +resolver = "2" \ No newline at end of file diff --git a/crates/nbt-test/Cargo.toml b/nbt-test/Cargo.toml similarity index 100% rename from crates/nbt-test/Cargo.toml rename to nbt-test/Cargo.toml diff --git a/crates/nbt-test/src/main.rs b/nbt-test/src/main.rs similarity index 86% rename from crates/nbt-test/src/main.rs rename to nbt-test/src/main.rs index 3f1c471..fb11510 100644 --- a/crates/nbt-test/src/main.rs +++ b/nbt-test/src/main.rs @@ -192,7 +192,6 @@ fn test_fastnbt(data: Vec) { } fn read_test(in_data: Vec) { - let len = in_data.len(); #[cfg(feature = "debug")] println!("data: {:?}", data); @@ -219,44 +218,65 @@ fn cli_read_test() { let mut args = std::env::args(); // 如果有, 取出 if let Some(arg) = args.nth(1) { - let data = std::fs::read(&arg).unwrap(); + let read_data = std::fs::read(&arg).unwrap(); // read_test(data); - let len = data.len(); - test_lib!( - { - let cursor: shen_nbt1::data::Reader = std::io::Cursor::new(data.as_slice()); - let nbt_data = shen_nbt1::data::NbtItem::try_from(cursor).unwrap(); + let len = read_data.len(); + let data = read_data; + + std::thread::sleep(std::time::Duration::from_secs(1)); + let start_time = std::time::Instant::now(); + let nbt_data = shen_nbt4::Value::from_vec(data); + let end_time = std::time::Instant::now(); + println!("=== shen nbt 4 ==="); + print!("time: {:?}", end_time - start_time); + println!(" speed: {:?} (bytes/sec)", len as f64 / (end_time - start_time).as_secs_f64()); + println!("{:?} (kb/sec)", len as f64 / (end_time - start_time).as_secs_f64() / 1024.0); + println!( + "{:?} (mb/sec)", + len as f64 / (end_time - start_time).as_secs_f64() / 1024.0 / 1024.0 + ); + println!( + "{:?} (gb/sec)", + len as f64 / (end_time - start_time).as_secs_f64() / 1024.0 / 1024.0 / 1024.0 + ); + #[cfg(feature = "core_debug")] + println!("nbt_data: {:#?}", nbt_data); + println!("nbt len {}", nbt_data.as_byte().is_some()); + // test_lib!( + // { + // let cursor: shen_nbt1::data::Reader = std::io::Cursor::new(data.as_slice()); + // let nbt_data = shen_nbt1::data::NbtItem::try_from(cursor).unwrap(); - }, "nbt v1", len - ); + // }, "nbt v1", len + // ); - let data2 = std::fs::read(&arg).unwrap(); - test_lib!( - { - let nbt_data = shen_nbt2::Value::from_vec(data2); - }, "nbt v2", len - ); + // let data2 = std::fs::read(&arg).unwrap(); + // test_lib!( + // { + // let nbt_data = shen_nbt2::Value::from_vec(data2); + // }, "nbt v2", len + // ); - let data3 = std::fs::read(&arg).unwrap(); - test_lib!( - { - let nbt_data = shen_nbt3::Value::from_vec(data3); - }, "nbt v3", len - ); + // let data3 = std::fs::read(&arg).unwrap(); + // test_lib!( + // { + // let nbt_data = shen_nbt3::Value::from_vec(data3); + // }, "nbt v3", len + // ); - let data4 = std::fs::read(&arg).unwrap(); - test_lib!( - { - let nbt_data = shen_nbt4::Value::from_vec(data4); - }, "nbt v4", len - ); + // let data4 = std::fs::read(&arg).unwrap(); + // test_lib!( + // { + // let nbt_data = shen_nbt4::Value::from_vec(data); + // }, "nbt v4", len + // ); - let data5 = std::fs::read(&arg).unwrap(); - test_lib!( - { - let nbt_data: fastnbt::Value = fastnbt::from_bytes(data5.as_slice()).unwrap(); - }, "fastnbt", len - ); + // let data5 = std::fs::read(&arg).unwrap(); + // test_lib!( + // { + // let nbt_data: fastnbt::Value = fastnbt::from_bytes(data5.as_slice()).unwrap(); + // }, "fastnbt", len + // ); } else { println!("Usage: cargo run --release -- "); } diff --git a/crates/shen-nbt1/Cargo.toml b/shen-nbt1/Cargo.toml similarity index 100% rename from crates/shen-nbt1/Cargo.toml rename to shen-nbt1/Cargo.toml diff --git a/crates/shen-nbt1/LICENSE b/shen-nbt1/LICENSE similarity index 100% rename from crates/shen-nbt1/LICENSE rename to shen-nbt1/LICENSE diff --git a/crates/shen-nbt1/src/data.rs b/shen-nbt1/src/data.rs similarity index 100% rename from crates/shen-nbt1/src/data.rs rename to shen-nbt1/src/data.rs diff --git a/crates/shen-nbt1/src/lib.rs b/shen-nbt1/src/lib.rs similarity index 100% rename from crates/shen-nbt1/src/lib.rs rename to shen-nbt1/src/lib.rs diff --git a/crates/shen-nbt1/src/read.rs b/shen-nbt1/src/read.rs similarity index 99% rename from crates/shen-nbt1/src/read.rs rename to shen-nbt1/src/read.rs index 67c97e3..bdeb029 100644 --- a/crates/shen-nbt1/src/read.rs +++ b/shen-nbt1/src/read.rs @@ -1,5 +1,4 @@ use crate::data::{NbtItem, NbtList, NbtValue, Reader}; -use std::convert::From; use std::io::{BufRead, Cursor, Read}; /// 输出类型标识符 diff --git a/crates/shen-nbt1/src/rustfmt.toml b/shen-nbt1/src/rustfmt.toml similarity index 100% rename from crates/shen-nbt1/src/rustfmt.toml rename to shen-nbt1/src/rustfmt.toml diff --git a/crates/shen-nbt2/Cargo.toml b/shen-nbt2/Cargo.toml similarity index 100% rename from crates/shen-nbt2/Cargo.toml rename to shen-nbt2/Cargo.toml diff --git a/crates/shen-nbt2/src/lib.rs b/shen-nbt2/src/lib.rs similarity index 100% rename from crates/shen-nbt2/src/lib.rs rename to shen-nbt2/src/lib.rs diff --git a/crates/shen-nbt2/src/rustfmt.toml b/shen-nbt2/src/rustfmt.toml similarity index 100% rename from crates/shen-nbt2/src/rustfmt.toml rename to shen-nbt2/src/rustfmt.toml diff --git a/crates/shen-nbt3/Cargo.toml b/shen-nbt3/Cargo.toml similarity index 100% rename from crates/shen-nbt3/Cargo.toml rename to shen-nbt3/Cargo.toml diff --git a/crates/shen-nbt3/src/lib.rs b/shen-nbt3/src/lib.rs similarity index 100% rename from crates/shen-nbt3/src/lib.rs rename to shen-nbt3/src/lib.rs diff --git a/crates/shen-nbt3/src/rustfmt.toml b/shen-nbt3/src/rustfmt.toml similarity index 100% rename from crates/shen-nbt3/src/rustfmt.toml rename to shen-nbt3/src/rustfmt.toml diff --git a/crates/shen-nbt4/Cargo.toml b/shen-nbt4/Cargo.toml similarity index 100% rename from crates/shen-nbt4/Cargo.toml rename to shen-nbt4/Cargo.toml diff --git a/crates/shen-nbt4/src/lib.rs b/shen-nbt4/src/lib.rs similarity index 100% rename from crates/shen-nbt4/src/lib.rs rename to shen-nbt4/src/lib.rs diff --git a/crates/shen-nbt4/src/rustfmt.toml b/shen-nbt4/src/rustfmt.toml similarity index 100% rename from crates/shen-nbt4/src/rustfmt.toml rename to shen-nbt4/src/rustfmt.toml diff --git a/shen-nbt5/Cargo.toml b/shen-nbt5/Cargo.toml new file mode 100644 index 0000000..eca3c35 --- /dev/null +++ b/shen-nbt5/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "shen-nbt5" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/shen-nbt5/src/main.rs b/shen-nbt5/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/shen-nbt5/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}