Skip to content

Instantly share code, notes, and snippets.

@Arkoniak
Created March 2, 2021 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arkoniak/6f8399522fc0d866cf5a400961ff5810 to your computer and use it in GitHub Desktop.
Save Arkoniak/6f8399522fc0d866cf5a400961ff5810 to your computer and use it in GitHub Desktop.
File for testing view speed
function f1(v)
v1 = deepcopy(v)
stats = @timed sort!(v1)
return stats.time*1.0e6
end
function f2(v)
v1 = deepcopy(v)
v2 = @views v1[500:1499]
stats = @timed sort!(v2)
return stats.time*1.0e6
end
function main(n = 100000)
v1 = parse.(Float64, split(read(joinpath(@__DIR__, "data.txt"), String)))
results = Vector{Float64}(undef, n)
for i in 1:n
results[i] = f1(v1)
end
m1 = minimum(results)
v2 = Vector{Float64}(undef, 2000)
v2[500:1499] .= v1
for i in 1:n
results[i] = f2(v2)
end
m2 = minimum(results)
return m1, m2
end
println(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment