You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-17Lines changed: 11 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ assert_eq!("This is just a test text.".as_bytes(), TEST);
47
47
assert_eq!("Some text...".as_bytes(), TEST2);
48
48
```
49
49
50
-
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str` when you are not using the **release** profile. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value or just use the `as_ref` method.
50
+
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str`. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value.
51
51
52
52
```rust
53
53
#[macro_use] externcrate lazy_static_include;
@@ -57,13 +57,7 @@ lazy_static_include_bytes! {
57
57
TEST=>"data/test.txt",
58
58
}
59
59
60
-
#[cfg(debug_assertions)]
61
60
letdata:&'static [u8] =*TEST;
62
-
63
-
#[cfg(not(debug_assertions))]
64
-
letdata:&'static [u8] =TEST;
65
-
66
-
letdata:&'static [u8] =TEST.as_ref();
67
61
```
68
62
69
63
## Include Array
@@ -102,18 +96,18 @@ assert_eq!("哈囉", TEST2[2]);
102
96
Using static mechanisms makes your program faster. See my benchmark result below (AMD Ryzen 9 3900X 12-Core Processor 12C/24T 3.90GHz, ran on 2020/07/02):
103
97
104
98
```text
105
-
test include_array_lazy_static ... bench: 45 ns/iter (+/- 3)
106
-
test include_array_native_static ... bench: 45 ns/iter (+/- 3)
107
-
test include_array_no_static ... bench: 20,959 ns/iter (+/- 295)
108
-
test include_bytes_lazy_static ... bench: 754 ns/iter (+/- 7)
109
-
test include_bytes_native_static ... bench: 755 ns/iter (+/- 11)
110
-
test include_bytes_no_static ... bench: 4,560 ns/iter (+/- 179)
111
-
test include_str_lazy_static ... bench: 753 ns/iter (+/- 10)
112
-
test include_str_native_static ... bench: 755 ns/iter (+/- 7)
113
-
test include_str_no_static ... bench: 4,830 ns/iter (+/- 198)
99
+
test include_array_lazy_static ... bench: 46 ns/iter (+/- 3)
100
+
test include_array_native_static ... bench: 48 ns/iter (+/- 3)
101
+
test include_array_no_static ... bench: 22,414 ns/iter (+/- 297)
102
+
test include_bytes_lazy_static ... bench: 844 ns/iter (+/- 3)
103
+
test include_bytes_native_static ... bench: 863 ns/iter (+/- 5)
104
+
test include_bytes_no_static ... bench: 4,764 ns/iter (+/- 189)
105
+
test include_str_lazy_static ... bench: 857 ns/iter (+/- 8)
106
+
test include_str_native_static ... bench: 842 ns/iter (+/- 10)
107
+
test include_str_no_static ... bench: 4,837 ns/iter (+/- 145)
114
108
```
115
109
116
-
When using the **release** profile, the performance of `lazy_static_include_*` is very close to `include_*` (in fast, they are the same). That means you don't need to worry about the overhead, but just enjoy the faster compilation time.
110
+
When using the **release** profile, the performance of `lazy_static_include_*` is very close to `include_*`. That means you don't need to worry about the overhead, but just enjoy the faster compilation time.
Copy file name to clipboardExpand all lines: src/lib.rs
+12-18Lines changed: 12 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -45,23 +45,17 @@ assert_eq!("This is just a test text.".as_bytes(), TEST);
45
45
assert_eq!("Some text...".as_bytes(), TEST2);
46
46
```
47
47
48
-
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str` when you are not using the **release** profile. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value or just use the `as_ref` method.
48
+
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str`. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value.
49
49
50
-
```rust,ignore
50
+
```rust
51
51
#[macro_use] extern crate lazy_static_include;
52
52
53
53
lazy_static_include_bytes! {
54
54
/// doc
55
55
TEST => "data/test.txt",
56
56
}
57
57
58
-
#[cfg(debug_assertions)]
59
58
let data: &'static [u8] = *TEST;
60
-
61
-
#[cfg(not(debug_assertions))]
62
-
let data: &'static [u8] = TEST;
63
-
64
-
let data: &'static [u8] = TEST.as_ref();
65
59
```
66
60
67
61
## Include Array
@@ -100,18 +94,18 @@ assert_eq!("哈囉", TEST2[2]);
100
94
Using static mechanisms makes your program faster. See my benchmark result below (AMD Ryzen 9 3900X 12-Core Processor 12C/24T 3.90GHz, ran on 2020/07/02):
101
95
102
96
```text
103
-
test include_array_lazy_static ... bench: 45 ns/iter (+/- 3)
104
-
test include_array_native_static ... bench: 45 ns/iter (+/- 3)
105
-
test include_array_no_static ... bench: 20,959 ns/iter (+/- 295)
106
-
test include_bytes_lazy_static ... bench: 754 ns/iter (+/- 7)
107
-
test include_bytes_native_static ... bench: 755 ns/iter (+/- 11)
108
-
test include_bytes_no_static ... bench: 4,560 ns/iter (+/- 179)
109
-
test include_str_lazy_static ... bench: 753 ns/iter (+/- 10)
110
-
test include_str_native_static ... bench: 755 ns/iter (+/- 7)
111
-
test include_str_no_static ... bench: 4,830 ns/iter (+/- 198)
97
+
test include_array_lazy_static ... bench: 46 ns/iter (+/- 3)
98
+
test include_array_native_static ... bench: 48 ns/iter (+/- 3)
99
+
test include_array_no_static ... bench: 22,414 ns/iter (+/- 297)
100
+
test include_bytes_lazy_static ... bench: 844 ns/iter (+/- 3)
101
+
test include_bytes_native_static ... bench: 863 ns/iter (+/- 5)
102
+
test include_bytes_no_static ... bench: 4,764 ns/iter (+/- 189)
103
+
test include_str_lazy_static ... bench: 857 ns/iter (+/- 8)
104
+
test include_str_native_static ... bench: 842 ns/iter (+/- 10)
105
+
test include_str_no_static ... bench: 4,837 ns/iter (+/- 145)
112
106
```
113
107
114
-
When using the **release** profile, the performance of `lazy_static_include_*` is very close to `include_*` (in fast, they are the same). That means you don't need to worry about the overhead, but just enjoy the faster compilation time.
108
+
When using the **release** profile, the performance of `lazy_static_include_*` is very close to `include_*`. That means you don't need to worry about the overhead, but just enjoy the faster compilation time.
0 commit comments