I want to write a function, which prints the runtime of any other function which take as an argument along with parameters. Example my idea in python for a better understanding:
def runtimer(func , *args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
print(time.time() - start)
return result
runtimer(time.sleep, 1)
Output: 1.000108242034912
I'm trying to use val: _*
parameter, but it implements "all or nothing". In another way I checked print
function in source scala github, but I did not find anything applicable to my question.
I would like to know if this is possible to solve on scala or get any advice. A java implementation will also be useful.
Thanks!
UPD: I will leave here some most useful references: the first for the most similar implementation, second maximum correct for runtime calculating on JVM (by comment): 1) How to profile methods in Scala? 2) Scala : function to measure the runtime of any other function
The question is still open, I'm waiting for discussions