@@ -378,6 +378,8 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
378
378
let print_mod = opt. niter / opt. print_count + 1 ;
379
379
let mut should_print = true ;
380
380
let mut print_header = true ;
381
+ let mut sample_weight: usize = 0 ;
382
+ let mut sample_alloc: usize = 0 ;
381
383
for key in 0 ..opt. niter {
382
384
should_print = should_print || key % print_mod == 0 ;
383
385
let before_mem = ALLOCATED . load ( SeqCst ) ;
@@ -407,15 +409,27 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
407
409
} ;
408
410
let before = ALLOCATED . load ( SeqCst ) ;
409
411
let sample = cacheable. sample ( size) ;
412
+ let weight = sample. weight ( ) ;
413
+ let alloc = ALLOCATED . load ( SeqCst ) - before;
414
+ sample_weight += weight;
415
+ sample_alloc += alloc;
410
416
if opt. samples {
411
- println ! (
412
- "sample: weight {:6} alloc {:6}" ,
413
- sample. weight( ) ,
414
- ALLOCATED . load( SeqCst ) - before,
415
- ) ;
417
+ println ! ( "sample: weight {:6} alloc {:6}" , weight, alloc, ) ;
416
418
}
417
419
cacheable. cache . insert ( key, * cacheable. sample ( size) ) ;
418
420
}
421
+ if sample_alloc == sample_weight {
422
+ println ! (
423
+ "samples: weight {} alloc {} weight/alloc precise" ,
424
+ sample_weight, sample_alloc
425
+ ) ;
426
+ } else {
427
+ let heap_factor = sample_alloc as f64 / sample_weight as f64 ;
428
+ println ! (
429
+ "samples: weight {} alloc {} weight/alloc {:0.2}" ,
430
+ sample_weight, sample_alloc, heap_factor
431
+ ) ;
432
+ }
419
433
}
420
434
421
435
/// This program constructs a template object of size `obj_size` and then
0 commit comments