MCPcopy Create free account
hub / github.com/evilsocket/cake / bench_serialization

Function bench_serialization

cake-core/tests/protocol.rs:387–431  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

385#[tokio::test]
386#[ignore]
387async fn bench_serialization() {
388 println!("\n=== Serialization Benchmark (to_writer + from_reader over duplex) ===\n");
389
390 let sizes: &[(usize, &str)] = &[
391 (64, "[1,64]"),
392 (512, "[1,512]"),
393 (2048, "[1,2048]"),
394 (5120, "[1,5120]"),
395 (8192, "[1,8192]"),
396 ];
397 let iterations = 1000;
398
399 for &(hidden_dim, label) in sizes {
400 let tensor = make_f16_tensor(&[1, hidden_dim]);
401 let tensor_bytes = hidden_dim * 2;
402
403 let (mut writer, mut reader) = tokio::io::duplex(256 * 1024);
404
405 let msg_for_write = Message::single_op("model.layers.0", &tensor, 0, 0);
406
407 // Spawn writer in background
408 let write_handle = tokio::spawn(async move {
409 for _ in 0..iterations {
410 // Re-create to include serialization cost
411 msg_for_write.to_writer(&mut writer).await.unwrap();
412 }
413 drop(writer);
414 });
415
416 let start = Instant::now();
417 for _ in 0..iterations {
418 let _ = Message::from_reader(&mut reader).await.unwrap();
419 }
420 let elapsed = start.elapsed();
421
422 write_handle.await.unwrap();
423
424 print_bench(
425 &format!("SingleOp F16 {}", label),
426 tensor_bytes,
427 elapsed,
428 iterations,
429 );
430 }
431}
432
433#[tokio::test]
434#[ignore]

Callers

nothing calls this directly

Calls 3

print_benchFunction · 0.85
to_writerMethod · 0.80
make_f16_tensorFunction · 0.70

Tested by

no test coverage detected