iscc-lib 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/core/Cargo.toml ADDED
@@ -0,0 +1,131 @@
1
+ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
2
+ #
3
+ # When uploading crates to the registry Cargo will automatically
4
+ # "normalize" Cargo.toml files for maximal compatibility
5
+ # with all versions of Cargo and also rewrite `path` dependencies
6
+ # to registry (e.g., crates.io) dependencies.
7
+ #
8
+ # If you are reading this file be aware that the original Cargo.toml
9
+ # will likely look very different (and much more reasonable).
10
+ # See Cargo.toml.orig for the original contents.
11
+
12
+ [package]
13
+ edition = "2024"
14
+ rust-version = "1.85"
15
+ name = "iscc-lib"
16
+ version = "0.8.0"
17
+ authors = ["Titusz Pan <tp@py7.de>"]
18
+ build = false
19
+ exclude = [
20
+ "tests/data-edge.json",
21
+ "tests/test_data_edge.rs",
22
+ ]
23
+ autolib = false
24
+ autobins = false
25
+ autoexamples = false
26
+ autotests = false
27
+ autobenches = false
28
+ description = "High-performance Rust implementation of ISO 24138:2024 (ISCC)"
29
+ homepage = "https://lib.iscc.codes"
30
+ readme = "README.md"
31
+ keywords = [
32
+ "iscc",
33
+ "content-id",
34
+ "media",
35
+ "fingerprint",
36
+ "iso",
37
+ ]
38
+ categories = [
39
+ "multimedia",
40
+ "encoding",
41
+ "cryptography",
42
+ ]
43
+ license = "Apache-2.0"
44
+ repository = "https://github.com/iscc/iscc-lib"
45
+ resolver = "2"
46
+
47
+ [features]
48
+ default = ["meta-code"]
49
+ meta-code = [
50
+ "text-processing",
51
+ "dep:serde_json_canonicalizer",
52
+ ]
53
+ text-processing = [
54
+ "dep:unicode-normalization",
55
+ "dep:unicode-general-category",
56
+ ]
57
+
58
+ [lib]
59
+ name = "iscc_lib"
60
+ path = "src/lib.rs"
61
+
62
+ [[test]]
63
+ name = "codec_clean"
64
+ path = "tests/codec_clean.rs"
65
+
66
+ [[test]]
67
+ name = "test_algorithm_primitives"
68
+ path = "tests/test_algorithm_primitives.rs"
69
+
70
+ [[test]]
71
+ name = "test_seq"
72
+ path = "tests/test_seq.rs"
73
+
74
+ [[test]]
75
+ name = "test_strict_base32"
76
+ path = "tests/test_strict_base32.rs"
77
+
78
+ [[test]]
79
+ name = "test_text_utils"
80
+ path = "tests/test_text_utils.rs"
81
+
82
+ [[bench]]
83
+ name = "benchmarks"
84
+ path = "benches/benchmarks.rs"
85
+ harness = false
86
+
87
+ [[bench]]
88
+ name = "iai_benches"
89
+ path = "benches/iai_benches.rs"
90
+ harness = false
91
+
92
+ [dependencies.blake3]
93
+ version = "1"
94
+
95
+ [dependencies.data-encoding]
96
+ version = "2"
97
+
98
+ [dependencies.hex]
99
+ version = "0.4"
100
+
101
+ [dependencies.serde_json]
102
+ version = "1"
103
+
104
+ [dependencies.serde_json_canonicalizer]
105
+ version = "0.3.2"
106
+ optional = true
107
+
108
+ [dependencies.thiserror]
109
+ version = "2"
110
+
111
+ [dependencies.unicode-general-category]
112
+ version = "1"
113
+ optional = true
114
+
115
+ [dependencies.unicode-normalization]
116
+ version = "0.1"
117
+ optional = true
118
+
119
+ [dev-dependencies.criterion]
120
+ version = "0.8"
121
+ features = ["html_reports"]
122
+
123
+ [dev-dependencies.iai-callgrind]
124
+ version = "0.16"
125
+
126
+ [dev-dependencies.serde]
127
+ version = "1"
128
+ features = ["derive"]
129
+
130
+ [dev-dependencies.tempfile]
131
+ version = "3"
data/core/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # iscc-lib
2
+
3
+ [![CI](https://github.com/iscc/iscc-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/iscc/iscc-lib/actions/workflows/ci.yml)
4
+ [![Crate](https://img.shields.io/crates/v/iscc-lib.svg)](https://crates.io/crates/iscc-lib)
5
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+
7
+ High-performance Rust implementation of [ISO 24138:2024](https://www.iso.org/standard/77899.html) --
8
+ International Standard Content Code (ISCC).
9
+
10
+ ## What is ISCC
11
+
12
+ The ISCC is a similarity-preserving fingerprint and identifier for digital media assets. ISCCs are
13
+ generated algorithmically from digital content, just like cryptographic hashes. However, instead of
14
+ using a single cryptographic hash function to identify data only, the ISCC uses various algorithms
15
+ to create a composite identifier that exhibits similarity-preserving properties (soft hash).
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ cargo add iscc-lib
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```rust
26
+ use iscc_lib::gen_meta_code_v0;
27
+
28
+ let result = gen_meta_code_v0("ISCC Test Document!", None, None, 64).unwrap();
29
+ println!("Meta-Code: {}", result.iscc);
30
+ ```
31
+
32
+ ## API Overview
33
+
34
+ ### Code Generators
35
+
36
+ | Function | Description |
37
+ | ---------------------- | -------------------------------------------- |
38
+ | `gen_meta_code_v0` | Generate a Meta-Code from metadata fields |
39
+ | `gen_text_code_v0` | Generate a Text-Code from plain text |
40
+ | `gen_image_code_v0` | Generate an Image-Code from pixel data |
41
+ | `gen_audio_code_v0` | Generate an Audio-Code from Chromaprint data |
42
+ | `gen_video_code_v0` | Generate a Video-Code from frame signatures |
43
+ | `gen_mixed_code_v0` | Generate a Mixed-Code from Content-Codes |
44
+ | `gen_data_code_v0` | Generate a Data-Code from raw bytes |
45
+ | `gen_instance_code_v0` | Generate an Instance-Code from raw bytes |
46
+ | `gen_iscc_code_v0` | Generate a composite ISCC-CODE |
47
+ | `gen_sum_code_v0` | Generate an ISCC-SUM from a file path |
48
+
49
+ ### Utilities
50
+
51
+ - **Text processing:** `text_clean`, `text_remove_newlines`, `text_trim`, `text_collapse`
52
+ - **Algorithm primitives:** `alg_simhash`, `alg_minhash_256`, `alg_cdc_chunks`, `sliding_window`
53
+ - **Soft hashing:** `soft_hash_video_v0`
54
+ - **Encoding:** `encode_base64`
55
+ - **Codec:** `iscc_decompose`, plus the `codec` module with header encoding/decoding primitives
56
+ - **Streaming:** `DataHasher`, `InstanceHasher` for incremental processing
57
+ - **Diagnostics:** `conformance_selftest`
58
+
59
+ ## Feature Flags
60
+
61
+ | Feature | Default | Adds |
62
+ | ----------------- | ------- | -------------------------------------------------------------------------- |
63
+ | `meta-code` | yes | `gen_meta_code_v0`, `json_to_data_url`, meta constants |
64
+ | `text-processing` | yes | `gen_text_code_v0`, `text_clean`, `text_collapse` (implied by `meta-code`) |
65
+
66
+ Data-Code, Instance-Code, ISCC-SUM, Image/Audio/Video/Mixed-Code, codec, and streaming are always
67
+ available regardless of feature flags.
68
+
69
+ For a minimal build with only ISCC-SUM support (Data-Code + Instance-Code):
70
+
71
+ ```bash
72
+ cargo add iscc-lib --no-default-features
73
+ ```
74
+
75
+ ## Links
76
+
77
+ - [Documentation](https://lib.iscc.codes)
78
+ - [Repository](https://github.com/iscc/iscc-lib)
79
+ - [ISCC Specification (ISO 24138)](https://www.iso.org/standard/77899.html)
80
+ - [ISCC Foundation](https://iscc.io)
81
+
82
+ ## License
83
+
84
+ Apache-2.0
@@ -0,0 +1,294 @@
1
+ //! Criterion benchmarks for all 10 `gen_*_v0` ISCC functions.
2
+ //!
3
+ //! Uses representative inline inputs (conformance-derived and synthetic) to
4
+ //! measure latency and throughput of the core ISCC generation functions.
5
+
6
+ use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
7
+ use iscc_lib::{
8
+ DataHasher, alg_cdc_chunks, gen_audio_code_v0, gen_data_code_v0, gen_image_code_v0,
9
+ gen_instance_code_v0, gen_iscc_code_v0, gen_meta_code_v0, gen_mixed_code_v0, gen_sum_code_v0,
10
+ gen_text_code_v0, gen_video_code_v0,
11
+ };
12
+ use std::hint::black_box;
13
+ use std::io::Write;
14
+ use tempfile::NamedTempFile;
15
+
16
+ /// Generate a deterministic byte buffer of the given size.
17
+ fn deterministic_bytes(size: usize) -> Vec<u8> {
18
+ (0..size).map(|i| (i % 256) as u8).collect()
19
+ }
20
+
21
+ /// Generate a synthetic text string of approximately the given character count.
22
+ fn synthetic_text(chars: usize) -> String {
23
+ let base = "The quick brown fox jumps over the lazy dog. ";
24
+ base.repeat((chars / base.len()) + 1)[..chars].to_string()
25
+ }
26
+
27
+ /// Benchmark `gen_meta_code_v0` with name-only and name+description inputs.
28
+ fn bench_meta_code(c: &mut Criterion) {
29
+ let mut group = c.benchmark_group("gen_meta_code_v0");
30
+
31
+ group.bench_function("name_only", |b| {
32
+ b.iter(|| {
33
+ gen_meta_code_v0(
34
+ black_box("Die Unendliche Geschichte"),
35
+ black_box(None),
36
+ black_box(None),
37
+ black_box(64),
38
+ )
39
+ .unwrap()
40
+ })
41
+ });
42
+
43
+ group.bench_function("name+desc", |b| {
44
+ b.iter(|| {
45
+ gen_meta_code_v0(
46
+ black_box("Die Unendliche Geschichte"),
47
+ black_box(Some("Von Michael Ende")),
48
+ black_box(None),
49
+ black_box(64),
50
+ )
51
+ .unwrap()
52
+ })
53
+ });
54
+
55
+ group.finish();
56
+ }
57
+
58
+ /// Benchmark `gen_text_code_v0` with a ~1000-character synthetic text.
59
+ fn bench_text_code(c: &mut Criterion) {
60
+ let mut group = c.benchmark_group("gen_text_code_v0");
61
+ let text = synthetic_text(1000);
62
+
63
+ group.bench_function("1000_chars", |b| {
64
+ b.iter(|| gen_text_code_v0(black_box(&text), black_box(64)).unwrap())
65
+ });
66
+
67
+ group.finish();
68
+ }
69
+
70
+ /// Benchmark `gen_image_code_v0` with a 1024-byte gradient pixel array.
71
+ fn bench_image_code(c: &mut Criterion) {
72
+ let mut group = c.benchmark_group("gen_image_code_v0");
73
+ let pixels: Vec<u8> = (0..1024).map(|i| (i % 256) as u8).collect();
74
+
75
+ group.bench_function("32x32_gradient", |b| {
76
+ b.iter(|| gen_image_code_v0(black_box(&pixels), black_box(64)).unwrap())
77
+ });
78
+
79
+ group.finish();
80
+ }
81
+
82
+ /// Benchmark `gen_audio_code_v0` with a 300-element sequential feature vector.
83
+ fn bench_audio_code(c: &mut Criterion) {
84
+ let mut group = c.benchmark_group("gen_audio_code_v0");
85
+ let cv: Vec<i32> = (0..300).collect();
86
+
87
+ group.bench_function("300_features", |b| {
88
+ b.iter(|| gen_audio_code_v0(black_box(&cv), black_box(64)).unwrap())
89
+ });
90
+
91
+ group.finish();
92
+ }
93
+
94
+ /// Benchmark `gen_video_code_v0` with 10 frames of 380-element vectors.
95
+ fn bench_video_code(c: &mut Criterion) {
96
+ let mut group = c.benchmark_group("gen_video_code_v0");
97
+ let frames: Vec<Vec<i32>> = (0..10)
98
+ .map(|f: i32| (0..380).map(move |i| f * 380 + i).collect())
99
+ .collect();
100
+
101
+ group.bench_function("10x380_frames", |b| {
102
+ b.iter(|| gen_video_code_v0(black_box(&frames), black_box(64)).unwrap())
103
+ });
104
+
105
+ group.finish();
106
+ }
107
+
108
+ /// Benchmark `gen_mixed_code_v0` with Content-Code strings from conformance tests.
109
+ fn bench_mixed_code(c: &mut Criterion) {
110
+ let mut group = c.benchmark_group("gen_mixed_code_v0");
111
+ let codes = ["EUA6GIKXN42IQV3S", "EIAUKMOUIOYZCKA5"];
112
+
113
+ group.bench_function("2_content_codes", |b| {
114
+ let code_refs: Vec<&str> = codes.to_vec();
115
+ b.iter(|| gen_mixed_code_v0(black_box(&code_refs), black_box(64)).unwrap())
116
+ });
117
+
118
+ group.finish();
119
+ }
120
+
121
+ /// Benchmark `gen_data_code_v0` at 64KB and 1MB sizes.
122
+ fn bench_data_code(c: &mut Criterion) {
123
+ let mut group = c.benchmark_group("gen_data_code_v0");
124
+
125
+ let data_64k = deterministic_bytes(64 * 1024);
126
+ group.throughput(Throughput::Bytes(data_64k.len() as u64));
127
+ group.bench_with_input(
128
+ BenchmarkId::new("throughput", "64KB"),
129
+ &data_64k,
130
+ |b, data| b.iter(|| gen_data_code_v0(black_box(data), black_box(64)).unwrap()),
131
+ );
132
+
133
+ let data_1m = deterministic_bytes(1024 * 1024);
134
+ group.throughput(Throughput::Bytes(data_1m.len() as u64));
135
+ group.bench_with_input(
136
+ BenchmarkId::new("throughput", "1MB"),
137
+ &data_1m,
138
+ |b, data| b.iter(|| gen_data_code_v0(black_box(data), black_box(64)).unwrap()),
139
+ );
140
+
141
+ group.finish();
142
+ }
143
+
144
+ /// Benchmark `gen_instance_code_v0` at 64KB and 1MB sizes.
145
+ fn bench_instance_code(c: &mut Criterion) {
146
+ let mut group = c.benchmark_group("gen_instance_code_v0");
147
+
148
+ let data_64k = deterministic_bytes(64 * 1024);
149
+ group.throughput(Throughput::Bytes(data_64k.len() as u64));
150
+ group.bench_with_input(
151
+ BenchmarkId::new("throughput", "64KB"),
152
+ &data_64k,
153
+ |b, data| b.iter(|| gen_instance_code_v0(black_box(data), black_box(64)).unwrap()),
154
+ );
155
+
156
+ let data_1m = deterministic_bytes(1024 * 1024);
157
+ group.throughput(Throughput::Bytes(data_1m.len() as u64));
158
+ group.bench_with_input(
159
+ BenchmarkId::new("throughput", "1MB"),
160
+ &data_1m,
161
+ |b, data| b.iter(|| gen_instance_code_v0(black_box(data), black_box(64)).unwrap()),
162
+ );
163
+
164
+ group.finish();
165
+ }
166
+
167
+ /// Benchmark `gen_iscc_code_v0` with 4 ISCC unit strings from conformance tests.
168
+ fn bench_iscc_code(c: &mut Criterion) {
169
+ let mut group = c.benchmark_group("gen_iscc_code_v0");
170
+ let codes = [
171
+ "AAAYPXW445FTYNJ3",
172
+ "EAARMJLTQCUWAND2",
173
+ "GABVVC5DMJJGYKZ4ZBYVNYABFFYXG",
174
+ "IADWIK7A7JTUAQ2D6QARX7OBEIK3OOUAM42LOBLCZ4ZOGDLRHMDL6TQ",
175
+ ];
176
+
177
+ group.bench_function("4_units", |b| {
178
+ let code_refs: Vec<&str> = codes.to_vec();
179
+ b.iter(|| gen_iscc_code_v0(black_box(&code_refs), black_box(false)).unwrap())
180
+ });
181
+
182
+ group.finish();
183
+ }
184
+
185
+ /// Benchmark `gen_sum_code_v0` at 64KB and 1MB sizes using temp files.
186
+ fn bench_sum_code(c: &mut Criterion) {
187
+ let mut group = c.benchmark_group("gen_sum_code_v0");
188
+
189
+ let data_64k = deterministic_bytes(64 * 1024);
190
+ let mut tmpfile_64k = NamedTempFile::new().expect("failed to create temp file");
191
+ tmpfile_64k
192
+ .write_all(&data_64k)
193
+ .expect("failed to write temp file");
194
+ let path_64k = tmpfile_64k.path().to_path_buf();
195
+ group.throughput(Throughput::Bytes(data_64k.len() as u64));
196
+ group.bench_with_input(
197
+ BenchmarkId::new("throughput", "64KB"),
198
+ &path_64k,
199
+ |b, path| {
200
+ b.iter(|| {
201
+ gen_sum_code_v0(
202
+ black_box(path),
203
+ black_box(64),
204
+ black_box(false),
205
+ black_box(false),
206
+ )
207
+ .unwrap()
208
+ })
209
+ },
210
+ );
211
+
212
+ let data_1m = deterministic_bytes(1024 * 1024);
213
+ let mut tmpfile_1m = NamedTempFile::new().expect("failed to create temp file");
214
+ tmpfile_1m
215
+ .write_all(&data_1m)
216
+ .expect("failed to write temp file");
217
+ let path_1m = tmpfile_1m.path().to_path_buf();
218
+ group.throughput(Throughput::Bytes(data_1m.len() as u64));
219
+ group.bench_with_input(
220
+ BenchmarkId::new("throughput", "1MB"),
221
+ &path_1m,
222
+ |b, path| {
223
+ b.iter(|| {
224
+ gen_sum_code_v0(
225
+ black_box(path),
226
+ black_box(64),
227
+ black_box(false),
228
+ black_box(false),
229
+ )
230
+ .unwrap()
231
+ })
232
+ },
233
+ );
234
+
235
+ group.finish();
236
+ }
237
+
238
+ /// Benchmark `DataHasher` streaming with 64 KiB update chunks on 1 MB data.
239
+ fn bench_data_hasher_streaming(c: &mut Criterion) {
240
+ let mut group = c.benchmark_group("DataHasher");
241
+ let data = deterministic_bytes(1024 * 1024);
242
+ let chunk_size = 64 * 1024;
243
+
244
+ group.throughput(Throughput::Bytes(data.len() as u64));
245
+ group.bench_function("streaming_1MB_64KB_chunks", |b| {
246
+ b.iter(|| {
247
+ let mut dh = DataHasher::new();
248
+ for chunk in data.chunks(chunk_size) {
249
+ dh.update(black_box(chunk));
250
+ }
251
+ dh.finalize(black_box(64)).unwrap()
252
+ })
253
+ });
254
+
255
+ group.finish();
256
+ }
257
+
258
+ /// Benchmark `alg_cdc_chunks` directly at various data sizes.
259
+ fn bench_cdc_chunks(c: &mut Criterion) {
260
+ let mut group = c.benchmark_group("alg_cdc_chunks");
261
+
262
+ for &size in &[4 * 1024, 64 * 1024, 1024 * 1024] {
263
+ let data = deterministic_bytes(size);
264
+ let label = match size {
265
+ 4096 => "4KB",
266
+ 65536 => "64KB",
267
+ 1048576 => "1MB",
268
+ _ => unreachable!(),
269
+ };
270
+ group.throughput(Throughput::Bytes(size as u64));
271
+ group.bench_with_input(BenchmarkId::new("throughput", label), &data, |b, data| {
272
+ b.iter(|| alg_cdc_chunks(black_box(data), black_box(false), black_box(1024)).unwrap())
273
+ });
274
+ }
275
+
276
+ group.finish();
277
+ }
278
+
279
+ criterion_group!(
280
+ benches,
281
+ bench_meta_code,
282
+ bench_text_code,
283
+ bench_image_code,
284
+ bench_audio_code,
285
+ bench_video_code,
286
+ bench_mixed_code,
287
+ bench_data_code,
288
+ bench_instance_code,
289
+ bench_iscc_code,
290
+ bench_sum_code,
291
+ bench_data_hasher_streaming,
292
+ bench_cdc_chunks,
293
+ );
294
+ criterion_main!(benches);
@@ -0,0 +1,171 @@
1
+ //! `iai-callgrind` instruction-count benchmarks for `iscc-lib`'s hot CPU paths.
2
+ //!
3
+ //! These benchmarks feed the v1.0.0 performance-regression gate (issue #3). Unlike the
4
+ //! wall-clock criterion suite in `benchmarks.rs`, callgrind measures instruction counts,
5
+ //! which are deterministic and stable across machines — ideal for a CI regression gate.
6
+ //!
7
+ //! The harness itself compiles without valgrind or `iai-callgrind-runner`; only *running*
8
+ //! the benches (`cargo bench --bench iai_benches`) needs valgrind, which the follow-up CI
9
+ //! slice installs on a valgrind-enabled Linux runner. Run locally with valgrind present via
10
+ //! `cargo bench -p iscc-lib --bench iai_benches`.
11
+ //!
12
+ //! Each `#[library_benchmark]` returns `black_box(...)` of the call result so the optimizer
13
+ //! cannot elide the work. Input construction lives in `#[bench::id(expr)]` argument
14
+ //! expressions, which iai-callgrind evaluates in the unmeasured setup phase — so only the
15
+ //! ISCC computation itself is counted.
16
+ //!
17
+ //! The `#[library_benchmark]` functions use plain `//` comments rather than `///` docstrings:
18
+ //! the proc macro iterates every attribute on the function and aborts on any it does not
19
+ //! recognize, and a `///` comment lowers to a `#[doc = "..."]` attribute that it rejects.
20
+ //! Helper functions (not macro-annotated) keep ordinary `///` docstrings.
21
+ //!
22
+ //! `gen_sum_code_v0` is intentionally deferred: it is a file-I/O wrapper whose instruction
23
+ //! count is syscall-dominated and would need an iai setup closure to create the temp file
24
+ //! outside the measured region. It is covered by the criterion suite for wall-clock timing.
25
+
26
+ use iai_callgrind::{library_benchmark, library_benchmark_group, main};
27
+ use iscc_lib::{
28
+ AudioCodeResult, DataCodeResult, ImageCodeResult, InstanceCodeResult, IsccCodeResult,
29
+ MetaCodeResult, MixedCodeResult, TextCodeResult, VideoCodeResult, alg_cdc_chunks,
30
+ alg_minhash_256, gen_audio_code_v0, gen_data_code_v0, gen_image_code_v0, gen_instance_code_v0,
31
+ gen_iscc_code_v0, gen_meta_code_v0, gen_mixed_code_v0, gen_text_code_v0, gen_video_code_v0,
32
+ };
33
+ use std::hint::black_box;
34
+
35
+ /// Generate a deterministic byte buffer of the given size.
36
+ fn deterministic_bytes(size: usize) -> Vec<u8> {
37
+ (0..size).map(|i| (i % 256) as u8).collect()
38
+ }
39
+
40
+ /// Generate a synthetic text string of approximately the given character count.
41
+ fn synthetic_text(chars: usize) -> String {
42
+ let base = "The quick brown fox jumps over the lazy dog. ";
43
+ base.repeat((chars / base.len()) + 1)[..chars].to_string()
44
+ }
45
+
46
+ /// Generate a spread-out feature vector of the given length for MinHash.
47
+ fn deterministic_features(count: usize) -> Vec<u32> {
48
+ (0..count as u32)
49
+ .map(|i| i.wrapping_mul(2_654_435_761))
50
+ .collect()
51
+ }
52
+
53
+ // Benchmark `gen_meta_code_v0` with name-only and name+description inputs.
54
+ #[library_benchmark]
55
+ #[bench::name_only("Die Unendliche Geschichte", None)]
56
+ #[bench::name_desc("Die Unendliche Geschichte", Some("Von Michael Ende"))]
57
+ fn bench_meta_code(name: &str, description: Option<&str>) -> MetaCodeResult {
58
+ black_box(
59
+ gen_meta_code_v0(
60
+ black_box(name),
61
+ black_box(description),
62
+ black_box(None),
63
+ black_box(64),
64
+ )
65
+ .unwrap(),
66
+ )
67
+ }
68
+
69
+ // Benchmark `gen_text_code_v0` with a ~1000-character synthetic text.
70
+ #[library_benchmark]
71
+ #[bench::chars_1000(synthetic_text(1000))]
72
+ fn bench_text_code(text: String) -> TextCodeResult {
73
+ black_box(gen_text_code_v0(black_box(&text), black_box(64)).unwrap())
74
+ }
75
+
76
+ // Benchmark `gen_image_code_v0` with a 1024-byte gradient pixel array.
77
+ #[library_benchmark]
78
+ #[bench::gradient_1024(deterministic_bytes(1024))]
79
+ fn bench_image_code(pixels: Vec<u8>) -> ImageCodeResult {
80
+ black_box(gen_image_code_v0(black_box(&pixels), black_box(64)).unwrap())
81
+ }
82
+
83
+ // Benchmark `gen_audio_code_v0` with a 300-element sequential feature vector.
84
+ #[library_benchmark]
85
+ #[bench::features_300((0..300).collect::<Vec<i32>>())]
86
+ fn bench_audio_code(cv: Vec<i32>) -> AudioCodeResult {
87
+ black_box(gen_audio_code_v0(black_box(&cv), black_box(64)).unwrap())
88
+ }
89
+
90
+ // Benchmark `gen_video_code_v0` with 10 frames of 380-element vectors.
91
+ #[library_benchmark]
92
+ #[bench::frames_10x380((0..10).map(|f: i32| (0..380).map(move |i| f * 380 + i).collect::<Vec<i32>>()).collect::<Vec<Vec<i32>>>())]
93
+ fn bench_video_code(frame_sigs: Vec<Vec<i32>>) -> VideoCodeResult {
94
+ black_box(gen_video_code_v0(black_box(&frame_sigs), black_box(64)).unwrap())
95
+ }
96
+
97
+ // Benchmark `gen_mixed_code_v0` with Content-Code strings from conformance tests.
98
+ #[library_benchmark]
99
+ #[bench::two_codes(vec!["EUA6GIKXN42IQV3S", "EIAUKMOUIOYZCKA5"])]
100
+ fn bench_mixed_code(codes: Vec<&'static str>) -> MixedCodeResult {
101
+ black_box(gen_mixed_code_v0(black_box(&codes), black_box(64)).unwrap())
102
+ }
103
+
104
+ // Benchmark `gen_data_code_v0` at 64KB and 1MB sizes.
105
+ #[library_benchmark]
106
+ #[bench::bytes_64k(deterministic_bytes(64 * 1024))]
107
+ #[bench::bytes_1m(deterministic_bytes(1024 * 1024))]
108
+ fn bench_data_code(data: Vec<u8>) -> DataCodeResult {
109
+ black_box(gen_data_code_v0(black_box(&data), black_box(64)).unwrap())
110
+ }
111
+
112
+ // Benchmark `gen_instance_code_v0` at 64KB and 1MB sizes.
113
+ #[library_benchmark]
114
+ #[bench::bytes_64k(deterministic_bytes(64 * 1024))]
115
+ #[bench::bytes_1m(deterministic_bytes(1024 * 1024))]
116
+ fn bench_instance_code(data: Vec<u8>) -> InstanceCodeResult {
117
+ black_box(gen_instance_code_v0(black_box(&data), black_box(64)).unwrap())
118
+ }
119
+
120
+ // Benchmark `gen_iscc_code_v0` with 4 ISCC unit strings from conformance tests.
121
+ #[library_benchmark]
122
+ #[bench::four_units(vec![
123
+ "AAAYPXW445FTYNJ3",
124
+ "EAARMJLTQCUWAND2",
125
+ "GABVVC5DMJJGYKZ4ZBYVNYABFFYXG",
126
+ "IADWIK7A7JTUAQ2D6QARX7OBEIK3OOUAM42LOBLCZ4ZOGDLRHMDL6TQ",
127
+ ])]
128
+ fn bench_iscc_code(codes: Vec<&'static str>) -> IsccCodeResult {
129
+ black_box(gen_iscc_code_v0(black_box(&codes), black_box(false)).unwrap())
130
+ }
131
+
132
+ // Benchmark `alg_cdc_chunks` directly at 4KB, 64KB, and 1MB data sizes.
133
+ //
134
+ // Returns the chunk count (the `Vec<&[u8]>` borrows from `data`, so it cannot escape the
135
+ // function); the heavy chunking work is fully measured before the length is taken.
136
+ #[library_benchmark]
137
+ #[bench::bytes_4k(deterministic_bytes(4 * 1024))]
138
+ #[bench::bytes_64k(deterministic_bytes(64 * 1024))]
139
+ #[bench::bytes_1m(deterministic_bytes(1024 * 1024))]
140
+ fn bench_cdc_chunks(data: Vec<u8>) -> usize {
141
+ black_box(
142
+ alg_cdc_chunks(black_box(&data), black_box(false), black_box(1024))
143
+ .unwrap()
144
+ .len(),
145
+ )
146
+ }
147
+
148
+ // Benchmark `alg_minhash_256` directly with a 1024-element feature vector.
149
+ #[library_benchmark]
150
+ #[bench::features_1024(deterministic_features(1024))]
151
+ fn bench_minhash_256(features: Vec<u32>) -> Vec<u8> {
152
+ black_box(alg_minhash_256(black_box(&features)).unwrap())
153
+ }
154
+
155
+ library_benchmark_group!(
156
+ name = iscc_benches;
157
+ benchmarks =
158
+ bench_meta_code,
159
+ bench_text_code,
160
+ bench_image_code,
161
+ bench_audio_code,
162
+ bench_video_code,
163
+ bench_mixed_code,
164
+ bench_data_code,
165
+ bench_instance_code,
166
+ bench_iscc_code,
167
+ bench_cdc_chunks,
168
+ bench_minhash_256,
169
+ );
170
+
171
+ main!(library_benchmark_groups = iscc_benches);