From f0632bb09a909b2087d2073ec73b2cab77d0371b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 26 Feb 2024 21:45:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=9B=AE=E5=BD=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 52 +++++++++-- Cargo.toml | 10 +++ {crates/nbt-test => nbt-test}/Cargo.toml | 0 {crates/nbt-test => nbt-test}/src/main.rs | 86 ++++++++++++------- {crates/shen-nbt1 => shen-nbt1}/Cargo.toml | 0 {crates/shen-nbt1 => shen-nbt1}/LICENSE | 0 {crates/shen-nbt1 => shen-nbt1}/src/data.rs | 0 {crates/shen-nbt1 => shen-nbt1}/src/lib.rs | 0 {crates/shen-nbt1 => shen-nbt1}/src/read.rs | 1 - .../shen-nbt1 => shen-nbt1}/src/rustfmt.toml | 0 {crates/shen-nbt2 => shen-nbt2}/Cargo.toml | 0 {crates/shen-nbt2 => shen-nbt2}/src/lib.rs | 0 .../shen-nbt2 => shen-nbt2}/src/rustfmt.toml | 0 {crates/shen-nbt3 => shen-nbt3}/Cargo.toml | 0 {crates/shen-nbt3 => shen-nbt3}/src/lib.rs | 0 .../shen-nbt3 => shen-nbt3}/src/rustfmt.toml | 0 {crates/shen-nbt4 => shen-nbt4}/Cargo.toml | 0 {crates/shen-nbt4 => shen-nbt4}/src/lib.rs | 0 .../shen-nbt4 => shen-nbt4}/src/rustfmt.toml | 0 shen-nbt5/Cargo.toml | 8 ++ shen-nbt5/src/main.rs | 3 + 21 files changed, 119 insertions(+), 41 deletions(-) create mode 100644 Cargo.toml rename {crates/nbt-test => nbt-test}/Cargo.toml (100%) rename {crates/nbt-test => nbt-test}/src/main.rs (86%) rename {crates/shen-nbt1 => shen-nbt1}/Cargo.toml (100%) rename {crates/shen-nbt1 => shen-nbt1}/LICENSE (100%) rename {crates/shen-nbt1 => shen-nbt1}/src/data.rs (100%) rename {crates/shen-nbt1 => shen-nbt1}/src/lib.rs (100%) rename {crates/shen-nbt1 => shen-nbt1}/src/read.rs (99%) rename {crates/shen-nbt1 => shen-nbt1}/src/rustfmt.toml (100%) rename {crates/shen-nbt2 => shen-nbt2}/Cargo.toml (100%) rename {crates/shen-nbt2 => shen-nbt2}/src/lib.rs (100%) rename {crates/shen-nbt2 => shen-nbt2}/src/rustfmt.toml (100%) rename {crates/shen-nbt3 => shen-nbt3}/Cargo.toml (100%) rename {crates/shen-nbt3 => shen-nbt3}/src/lib.rs (100%) rename {crates/shen-nbt3 => shen-nbt3}/src/rustfmt.toml (100%) rename {crates/shen-nbt4 => shen-nbt4}/Cargo.toml (100%) rename {crates/shen-nbt4 => shen-nbt4}/src/lib.rs (100%) rename {crates/shen-nbt4 => shen-nbt4}/src/rustfmt.toml (100%) create mode 100644 shen-nbt5/Cargo.toml create mode 100644 shen-nbt5/src/main.rs 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!"); +}