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
description= "This crate provides `lazy_static_include_bytes` and `lazy_static_include_str` macros to replace `include_bytes` and `include_str` macros."
10
+
description= "This crate provides `lazy_static_include_bytes` and `lazy_static_include_str` macros to replace `include_bytes` and `include_str` macros."
11
11
readme = "README.md"
12
12
license = "MIT"
13
13
include = ["src/**/*", "Cargo.toml", "benches/bench.rs"]
assert_eq!("This is just a test text.".as_bytes(), TEST[0]);
40
-
assert_eq!(TEST[1], "Some text...".as_bytes());
46
+
assert_eq!(b"This is just a test text.".as_ref(), TEST);
47
+
assert_eq!(TEST2, b"Some text...".as_ref());
41
48
```
42
49
43
-
You should notice that the struct created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str`.
44
-
If you want to get an exact `&'static [u8]` or `&'static str` reference, you need to **dereference the struct**.
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.
@@ -72,64 +74,46 @@ The array is fixed sized and can be one of these following types: `bool`, `char`
72
74
Also, the `lazy_static_include_array` macro includes data from files into the compiled executable binary file **only** when you are using the **release** profile.
73
75
Be careful when you distribute your program.
74
76
77
+
The paths used for `lazy_static_include_array` are relative to **CARGO_MANIFEST_DIR**.
Using static mechanisms makes your program faster. See my benchmark result below (Intel i7-6700HQ, ran on 2019/07/16):
102
+
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):
119
103
120
104
```text
121
-
test include_array_lazy_static ... bench: 43 ns/iter (+/- 3)
122
-
test include_array_native_static ... bench: 46 ns/iter (+/- 4)
123
-
test include_array_no_static ... bench: 29,714 ns/iter (+/- 1,156)
124
-
test include_bytes_lazy_static ... bench: 382 ns/iter (+/- 63)
125
-
test include_bytes_native_static ... bench: 380 ns/iter (+/- 30)
126
-
test include_bytes_no_static ... bench: 9,076 ns/iter (+/- 1,224)
127
-
test include_str_lazy_static ... bench: 932 ns/iter (+/- 103)
128
-
test include_str_native_static ... bench: 937 ns/iter (+/- 25)
129
-
test include_str_no_static ... bench: 10,135 ns/iter (+/- 1,634)
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)
130
114
```
131
115
132
-
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.
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.
0 commit comments