(path: &Path)
| 52 | Ok(()) |
| 53 | } |
| 54 | fn measure(path: &Path) -> Result<Row> { |
| 55 | let original = fs::read(path)?; |
| 56 | let (mut change, hash) = Change::deserialize(&mut original.as_slice())?; |
| 57 | change.signature = None; |
| 58 | change.graph_encoding = atomic_core::change::format_v3::graph_fields::GraphEncoding::Raw; |
| 59 | change.semantic_encoding = SemanticEncoding::Raw; |
| 60 | let mut baseline = vec![]; |
| 61 | change.serialize(&mut baseline)?; |
| 62 | if !change.file_ops().is_empty() { |
| 63 | change.semantic_encoding = SemanticEncoding::Compact; |
| 64 | let mut compact = vec![]; |
| 65 | change.serialize(&mut compact)?; |
| 66 | if compact.len() < baseline.len() { |
| 67 | baseline = compact; |
| 68 | } |
| 69 | } |
| 70 | let mut input = baseline.as_slice(); |
| 71 | let mut reader = ChangeReader::open(&mut input)?; |
| 72 | let mut graph_bytes = 0; |
| 73 | let mut candidate_graph_bytes = 0; |
| 74 | let mut selected_graph_bytes = 0; |
| 75 | let mut encode_ms = 0.; |
| 76 | let mut decode_ms = 0.; |
| 77 | let mut baseline_graph_decode_ms = 0.; |
| 78 | let mut semantic_bytes = 0; |
| 79 | while let Some(section) = reader.next_section()? { |
| 80 | if section.section_type == SectionType::Semantic { |
| 81 | semantic_bytes += section.compressed_size as usize; |
| 82 | } |
| 83 | if section.section_type == SectionType::Graph { |
| 84 | graph_bytes += section.compressed_size as usize; |
| 85 | let graph = GraphSectionPayload::from_postcard_bytes(§ion.payload)?; |
| 86 | ensure!( |
| 87 | postcard::to_allocvec(&graph)? == section.payload, |
| 88 | "graph serialization is not the measured reference" |
| 89 | ); |
| 90 | let baseline_frame = zstd::encode_all(section.payload.as_slice(), 3)?; |
| 91 | ensure!( |
| 92 | baseline_frame.len() == section.compressed_size as usize, |
| 93 | "graph baseline compression differs" |
| 94 | ); |
| 95 | let start = Instant::now(); |
| 96 | let raw = zstd::decode_all(baseline_frame.as_slice())?; |
| 97 | let parsed = GraphSectionPayload::from_postcard_bytes(&raw)?; |
| 98 | baseline_graph_decode_ms += start.elapsed().as_secs_f64() * 1000.; |
| 99 | ensure!(parsed == graph, "graph baseline differs"); |
| 100 | drop(parsed); |
| 101 | drop(raw); |
| 102 | let start = Instant::now(); |
| 103 | let encoded = codec::encode(&graph)?; |
| 104 | encode_ms += start.elapsed().as_secs_f64() * 1000.; |
| 105 | let start = Instant::now(); |
| 106 | let restored = codec::decode(&encoded)?; |
| 107 | let parsed = GraphSectionPayload::from_postcard_bytes(&restored)?; |
| 108 | decode_ms += start.elapsed().as_secs_f64() * 1000.; |
| 109 | ensure!(restored == section.payload, "graph payload bytes changed"); |
| 110 | ensure!(parsed == graph, "graph operations changed"); |
| 111 | candidate_graph_bytes += encoded.len(); |
no test coverage detected