Last active
December 30, 2015 17:49
-
-
Save ivarne/7863449 to your computer and use it in GitHub Desktop.
This file contains 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
function old_colon{T<:Integer}(start::T, step::T, stop::T) | |
Range(start, step, max(0, div(stop-start+step, step))) | |
end | |
function new_colon{T<:Integer}(start::T, step::T, stop::T) | |
len,rem = divrem(stop-start,step) | |
Range(start, step, max(0, len+div(rem+step,step))) | |
end | |
function range_test_old() | |
for start = -1000:1000, stop = start-1000:10:start+1000, step=-31:2:30 | |
r=old_colon(start,step,stop) | |
end | |
end | |
function range_test_new() | |
for start = -1000:1000, stop = start-1000:10:start+1000, step=-31:2:30 | |
r=new_colon(start,step,stop) | |
end | |
end | |
println("Old") | |
@time range_test_old(); | |
@time range_test_old(); | |
@time range_test_old(); | |
@time range_test_old(); | |
@time range_test_old(); | |
println("New") | |
@time range_test_new(); | |
@time range_test_new(); | |
@time range_test_new(); | |
@time range_test_new(); | |
@time range_test_new(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment