Skip to content

Instantly share code, notes, and snippets.

@nalimilan
Last active October 13, 2018 09:58
Show Gist options
  • Save nalimilan/e69d361e1a5982c98587ed59c5600583 to your computer and use it in GitHub Desktop.
Save nalimilan/e69d361e1a5982c98587ed59c5600583 to your computer and use it in GitHub Desktop.
function f(df)
x = 0.0
cols = DataFrames.columns(df)
for i in 1:nrow(df)
t = ntuple(j -> cols[j][i], ncol(df))
x += t[1]
end
x
end
function g(df)
x = 0.0
for i in 1:nrow(df)
r = DataFrameRow(df, i)
x += r[1]
end
x
end
using DataFrames, BenchmarkTools
df = DataFrame(x=rand(1000), y=rand(1000))
df2 = DataFrame(rand(1000, 100))
julia> @btime f(df);
279.796 μs (6979 allocations: 140.30 KiB)
julia> @btime f(df2);
6.715 ms (256901 allocations: 5.58 MiB)
julia> @btime g(df);
40.277 μs (2490 allocations: 38.91 KiB)
julia> @btime g(df2);
40.183 μs (2490 allocations: 38.91 KiB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment