Created
May 9, 2017 19:26
-
-
Save JeffBezanson/a5f4abd6f093795f7d8c41501fb94d8b to your computer and use it in GitHub Desktop.
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
immutable Myo{C} | |
c::C | |
function (::Type{Myo{C}}){C}(c) | |
if 2 == 2 # expansion of @assert 2==2 | |
nothing | |
else | |
throw(Base.AssertionError("2 == 2")) | |
end | |
return new{C}(c) | |
end | |
end | |
foo() = Myo{Type{Int}}(Int) | |
for i=1:100;foo();end | |
@time for i=1:10000;foo();end # 1 | |
const f32 = 0 | |
jltype(::Val{f32}) = Float32 | |
get_type(i) = jltype(Val{i}()) | |
for i=1:100;get_type(f32);end | |
@time for i=1:10000;get_type(f32);end # 2 | |
function _sortperm!(v::AbstractVector; | |
lt=isless, | |
by=identity, | |
rev::Bool=false, | |
order::Base.Ordering=Base.Order.Forward) | |
order = Base.Order.ord(lt,by,rev,order) | |
p = Base.Order.Perm(order, v) | |
end | |
v = rand(12) | |
_sortperm!(v) | |
@time for i=1:10000;_sortperm!(v);end # 3 | |
immutable f{t} | |
end | |
(::f{t}){t}(x) = t | |
for i=1:1000; f{i}()(1); end | |
@time for i=1:1000; f{i}()(1); end # 4 | |
for i = 800:1000 # 5 | |
g = f{i}() # 6 | |
if i > 998 | |
@time for i=1:10000; g(Int); end | |
else | |
for i=1:10000; g(Int); end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment