Created
August 5, 2014 16:39
-
-
Save vchuravy/f25d31ef2e798ea21cc0 to your computer and use it in GitHub Desktop.
Julia
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
x = {[1:100]...} | |
function f1(X) | |
T = None | |
for x in X | |
T = promote_type(T,typeof(x)) | |
end | |
return T | |
end | |
function f2(X) | |
T = promote_type(map(typeof,X)...) | |
return T | |
end | |
function f3(X) | |
T = reduce((acc, x) -> promote_type(acc, typeof(x)), None, X) | |
return T | |
end | |
inner(acc, x) = promote_type(acc, typeof(x)) | |
function f4(X) | |
T = reduce(inner, None, X) | |
return T | |
end | |
num_iter = 1000 | |
f1(x) | |
f2(x) | |
f3(x) | |
f4(x) | |
println("f1") | |
@time for i in 1:num_iter | |
f1(x) | |
end | |
println("f2") | |
@time for i in 1:num_iter | |
f2(x) | |
end | |
println("f3") | |
@time for i in 1:num_iter | |
f3(x) | |
end | |
println("f4") | |
@time for i in 1:num_iter | |
f4(x) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment