Skip to content

Commit 81aaff5

Browse files
authored
Merge pull request #38 from Shopify/memory-usage-accuracy
feat: changed the position of metrics calculations
2 parents 876e8eb + 65ef72e commit 81aaff5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/engine.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ pub fn run(function_path: PathBuf, input_path: PathBuf) -> Result<FunctionRunRes
4444

4545
linker.module(&mut store, "Function", &module)?;
4646

47+
let instance = linker.instantiate(&mut store, &module)?;
48+
4749
let start = Instant::now();
4850

49-
let instance = linker.instantiate(&mut store, &module)?;
51+
let module_result = instance
52+
.get_typed_func::<(), (), _>(&mut store, "_start")?
53+
.call(&mut store, ());
54+
55+
runtime = start.elapsed();
5056

5157
// This is a hack to get the memory usage. Wasmtime requires a mutable borrow to a store for caching.
5258
// We need this mutable borrow to fall out of scope so that we can mesure memory usage.
@@ -67,12 +73,6 @@ pub fn run(function_path: PathBuf, input_path: PathBuf) -> Result<FunctionRunRes
6773
.sum::<u64>()
6874
* KB_PER_PAGE;
6975

70-
let module_result = instance
71-
.get_typed_func::<(), (), _>(&mut store, "_start")?
72-
.call(&mut store, ());
73-
74-
runtime = start.elapsed();
75-
7676
match module_result {
7777
Ok(_) => {}
7878
Err(e) => {

0 commit comments

Comments
 (0)