Skip to content

Commit 6e9eee7

Browse files
committed
graph: Force stress example to allocate on the heap
1 parent d8a946e commit 6e9eee7

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

graph/examples/stress.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::collections::{BTreeMap, HashMap};
33
use std::iter::FromIterator;
44
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
55

6-
use graph::prelude::q;
6+
use graph::components::store::EntityType;
7+
use graph::prelude::{q, DeploymentHash, EntityKey};
78
use rand::{thread_rng, Rng};
89
use structopt::StructOpt;
910

@@ -48,7 +49,7 @@ trait Template<T>: CacheWeight + Default {
4849
// Return a sample of this test object of the given `size`. There's no
4950
// fixed definition of 'size', other than that smaller sizes will
5051
// take less memory than larger ones
51-
fn sample(&self, size: usize) -> Self::Item;
52+
fn sample(&self, size: usize) -> Box<Self::Item>;
5253
}
5354

5455
/// Template for testing caching of `String`
@@ -62,8 +63,8 @@ impl Template<String> for String {
6263
}
6364
s
6465
}
65-
fn sample(&self, size: usize) -> Self::Item {
66-
self[0..size].into()
66+
fn sample(&self, size: usize) -> Box<Self::Item> {
67+
Box::new(self[0..size].into())
6768
}
6869
}
6970

@@ -74,8 +75,8 @@ impl Template<Vec<usize>> for Vec<usize> {
7475
fn create(size: usize) -> Self {
7576
Vec::from_iter(0..size)
7677
}
77-
fn sample(&self, size: usize) -> Self::Item {
78-
self[0..size].into()
78+
fn sample(&self, size: usize) -> Box<Self::Item> {
79+
Box::new(self[0..size].into())
7980
}
8081
}
8182

@@ -91,12 +92,12 @@ impl Template<HashMap<String, String>> for HashMap<String, String> {
9192
map
9293
}
9394

94-
fn sample(&self, size: usize) -> Self::Item {
95-
HashMap::from_iter(
95+
fn sample(&self, size: usize) -> Box<Self::Item> {
96+
Box::new(HashMap::from_iter(
9697
self.iter()
9798
.take(size)
9899
.map(|(k, v)| (k.to_owned(), v.to_owned())),
99-
)
100+
))
100101
}
101102
}
102103

@@ -135,12 +136,12 @@ impl Template<ValueMap> for ValueMap {
135136
map
136137
}
137138

138-
fn sample(&self, size: usize) -> Self::Item {
139-
BTreeMap::from_iter(
139+
fn sample(&self, size: usize) -> Box<Self::Item> {
140+
Box::new(BTreeMap::from_iter(
140141
self.iter()
141142
.take(size)
142143
.map(|(k, v)| (k.to_owned(), v.to_owned())),
143-
)
144+
))
144145
}
145146
}
146147

@@ -158,7 +159,7 @@ impl<T: Template<T>> Cacheable<T> {
158159
}
159160
}
160161

161-
fn sample(&self, size: usize) -> T::Item {
162+
fn sample(&self, size: usize) -> Box<T::Item> {
162163
self.template.sample(size)
163164
}
164165

@@ -234,7 +235,7 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
234235
ALLOCATED.load(SeqCst) - before,
235236
);
236237
}
237-
cacheable.cache.insert(key, cacheable.sample(size));
238+
cacheable.cache.insert(key, *cacheable.sample(size));
238239
}
239240
}
240241

0 commit comments

Comments
 (0)