Function runs slow when called on new/different arguments?

42 views
Skip to first unread message

Michael Wooley

unread,
Oct 26, 2016, 4:16:55 PM10/26/16
to julia-users
Hi, I'm trying to speed up some code and have found something curious that I can't quite understand from the "performance tips" section. 

I understand that I shouldn't time my code on the first run because that will include compilation time and so forth. 

The odd thing that I can't understand is that there seems to be a lot of overhead every time I pass an new argument to my function. So, e.g.,

# Create two instances of type test
test1 = test()
test2 = test()
# Run to get in cache - slow (as expected)
foo!(test1)
# Run again - fast (as expected)
foo!(test1)
# Run on test2   - Slow (not expected. should be fast because foo!() in cache?)
@time foo!(test2)
# Run on test2 again - fast (??)
@time foo!(test2)

I have used @code_warntype to try to get rid of type instability in my code to no avail. 

I know that the main bottleneck in my code is a triple-nested loop over large arrays.

I recognize that my pseudo-example is kind of vague but thought I'd try this first in case this sort of behavior is indicative of a basic issue that I've overlooked. I can provide my full code if that would be helpful. Thanks in advance! 

Andrew

unread,
Oct 26, 2016, 5:22:09 PM10/26/16
to julia-users
What's "slow?"

foo() is cached but @time isn't. Are you sure you're not timing the @time macro on your 3rd run?
Reply all
Reply to author
Forward
0 new messages