Last active
July 21, 2020 14:00
-
-
Save franciscocpg/19cfbf1ab7799f3b9c1e9c9b716a8e4d to your computer and use it in GitHub Desktop.
Measure execution time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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