Skip to content

Instantly share code, notes, and snippets.

@franciscocpg
Last active July 21, 2020 14:00
Show Gist options
  • Select an option

  • Save franciscocpg/19cfbf1ab7799f3b9c1e9c9b716a8e4d to your computer and use it in GitHub Desktop.

Select an option

Save franciscocpg/19cfbf1ab7799f3b9c1e9c9b716a8e4d to your computer and use it in GitHub Desktop.
Measure execution time
async measure(id, f) {
const finalId = `${id}-${new Date().getTime()}`;
console.time(finalId);
const res = await f();
console.timeEnd(finalId);
return res;
}
/**
Example
measure('test', () => doSomethingExpensive());
*/
from timeit import default_timer as timer
start = timer()
# {code_block}
# Change code_block_id for something that identifies the code block execution
print(f"code_block_id: {timer() - start}s") # Result in seconds
def time[R](block: => R, id: String): R = {
val t0 = System.currentTimeMillis()
val result = block
val t1 = System.currentTimeMillis()
println(s"Elapsed time for $id " + (t1 - t0) + "ms") // Result in milliseconds
result
}
/*
Example
time({code_block}, {code_block_id})
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment