Skip to content

Commit

Permalink
Add pinned memory cache benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Jan 12, 2021
1 parent e26868a commit f8f6785
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ fn bench_cache(c: &mut Criterion) {
let _ = cache
.get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
assert_eq!(cache.stats().hits_memory_cache, 0);
assert!(cache.stats().hits_fs_cache >= 1);
assert_eq!(cache.stats().misses, 0);
Expand All @@ -135,8 +136,33 @@ fn bench_cache(c: &mut Criterion) {
let _ = cache
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
assert!(cache.stats().hits_memory_cache >= 1);
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().misses, 0);
});
});

group.bench_function("instantiate from pinned memory", |b| {
let checksum = Checksum::generate(CONTRACT);
let mut cache: Cache<MockApi, MockStorage, MockQuerier> =
unsafe { Cache::new(options.clone()).unwrap() };
// Load into memory
cache
.get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS)
.unwrap();

// Pin
cache.pin(&checksum).unwrap();

b.iter(|| {
let backend = mock_backend(&[]);
let _ = cache
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_memory_cache, 1);
assert!(cache.stats().hits_pinned_memory_cache >= 1);
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().misses, 0);
});
});
Expand Down

0 comments on commit f8f6785

Please sign in to comment.