-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use multithreading in basic operations (#2647)
- Loading branch information
Showing
9 changed files
with
261 additions
and
33 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
benchmarks/constructor_and_indexing/constructor_and_indexing_performance.jl
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using BenchmarkTools | ||
using DataFrames | ||
using PooledArrays | ||
using Random | ||
|
||
@show Threads.nthreads() | ||
|
||
Random.seed!(1234) | ||
ref_dfi = DataFrame(rand(1:10^4, 10^7, 4), :auto) | ||
ref_dfs = string.(ref_dfi) | ||
ref_dfp = mapcols(PooledArray, ref_dfs) | ||
|
||
res = DataFrame(rows=Int[],cols=Int[], type=String[], op=String[], time=Float64[]) | ||
|
||
for x in (10, 10^6-1, 10^6, 10^7), y in 1:4 | ||
dfi = ref_dfi[1:x, 1:y] | ||
dfs = ref_dfs[1:x, 1:y] | ||
dfp = ref_dfp[1:x, 1:y] | ||
|
||
@show (x, y) # ping that the process is alive | ||
push!(res, (x, y, "integer", "copy", @belapsed DataFrame($dfi))) | ||
push!(res, (x, y, "string", "copy", @belapsed DataFrame($dfs))) | ||
push!(res, (x, y, "pooled", "copy", @belapsed DataFrame($dfp))) | ||
push!(res, (x, y, "integer", ":", @belapsed $dfi[:, :])) | ||
push!(res, (x, y, "string", ":", @belapsed $dfs[:, :])) | ||
push!(res, (x, y, "pooled", ":", @belapsed $dfp[:, :])) | ||
push!(res, (x, y, "integer", "1:end-5", @belapsed $dfi[1:end-5, :])) | ||
push!(res, (x, y, "string", "1:end-5", @belapsed $dfs[1:end-5, :])) | ||
push!(res, (x, y, "pooled", "1:end-5", @belapsed $dfp[1:end-5, :])) | ||
push!(res, (x, y, "integer", "1:5", @belapsed $dfi[1:5, :])) | ||
push!(res, (x, y, "string", "1:5", @belapsed $dfs[1:1:5, :])) | ||
push!(res, (x, y, "pooled", "1:5", @belapsed $dfp[1:1:5, :])) | ||
end | ||
|
||
res.time *= 1_000 | ||
|
||
@show Threads.nthreads() | ||
@show unstack(res, [:cols, :type, :op], :rows, :time) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
julia -t 1 constructor_and_indexing_performance.jl | ||
julia -t 2 constructor_and_indexing_performance.jl | ||
julia -t 4 constructor_and_indexing_performance.jl |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using CategoricalArrays | ||
using DataFrames | ||
using PooledArrays | ||
using Random | ||
|
||
fullgc() = (GC.gc(true); GC.gc(true); GC.gc(true); GC.gc(true)) | ||
|
||
@assert length(ARGS) == 7 | ||
@assert ARGS[3] in ["int", "pool", "cat", "str"] | ||
@assert ARGS[4] in ["uniq", "dup", "manydup"] | ||
@assert ARGS[5] in ["sort", "rand"] | ||
@assert ARGS[6] in ["1", "2"] | ||
@assert ARGS[7] in ["inner", "left", "right", "outer", "semi", "anti"] | ||
|
||
@info ARGS | ||
|
||
llen = parse(Int, ARGS[1]) | ||
rlen = parse(Int, ARGS[2]) | ||
@assert llen > 1000 | ||
@assert rlen > 2000 | ||
|
||
pad = maximum(length.(string.((llen, rlen)))) | ||
|
||
if ARGS[3] == "int" | ||
if ARGS[4] == "uniq" | ||
col1 = [1:llen;] | ||
col2 = [1:rlen;] | ||
elseif ARGS[4] == "dup" | ||
col1 = repeat(1:llen ÷ 2, inner=2) | ||
col2 = repeat(1:rlen ÷ 2, inner=2) | ||
else | ||
@assert ARGS[4] == "manydup" | ||
col1 = repeat(1:llen ÷ 20, inner=20) | ||
col2 = repeat(1:rlen ÷ 20, inner=20) | ||
end | ||
elseif ARGS[3] == "pool" | ||
if ARGS[4] == "dup" | ||
col1 = PooledArray(repeat(string.(1:llen ÷ 2, pad=pad), inner=2)) | ||
col2 = PooledArray(repeat(string.(1:rlen ÷ 2, pad=pad), inner=2)) | ||
else | ||
@assert ARGS[4] == "manydup" | ||
col1 = PooledArray(repeat(string.(1:llen ÷ 20, pad=pad), inner=20)) | ||
col2 = PooledArray(repeat(string.(1:rlen ÷ 20, pad=pad), inner=20)) | ||
end | ||
elseif ARGS[3] == "cat" | ||
if ARGS[4] == "dup" | ||
col1 = categorical(repeat(string.(1:llen ÷ 2, pad=pad), inner=2)) | ||
col2 = categorical(repeat(string.(1:rlen ÷ 2, pad=pad), inner=2)) | ||
else | ||
@assert ARGS[4] == "manydup" | ||
col1 = categorical(repeat(string.(1:llen ÷ 20, pad=pad), inner=20)) | ||
col2 = categorical(repeat(string.(1:rlen ÷ 20, pad=pad), inner=20)) | ||
end | ||
else | ||
@assert ARGS[3] == "str" | ||
if ARGS[4] == "uniq" | ||
col1 = string.(1:llen, pad=pad) | ||
col2 = string.(1:rlen, pad=pad) | ||
elseif ARGS[4] == "dup" | ||
col1 = repeat(string.(1:llen ÷ 2, pad=pad), inner=2) | ||
col2 = repeat(string.(1:rlen ÷ 2, pad=pad), inner=2) | ||
else | ||
@assert ARGS[4] == "manydup" | ||
col1 = repeat(string.(1:llen ÷ 20, pad=pad), inner=20) | ||
col2 = repeat(string.(1:rlen ÷ 20, pad=pad), inner=20) | ||
end | ||
end | ||
|
||
Random.seed!(1234) | ||
|
||
if ARGS[5] == "rand" | ||
shuffle!(col1) | ||
shuffle!(col2) | ||
else | ||
@assert ARGS[5] == "sort" | ||
end | ||
|
||
const joinfun = Dict("inner" => innerjoin, "left" => leftjoin, | ||
"right" => rightjoin, "outer" => outerjoin, | ||
"semi" => semijoin, "anti" => antijoin)[ARGS[7]] | ||
|
||
if ARGS[6] == "1" | ||
df1 = DataFrame(id1 = col1) | ||
df2 = DataFrame(id1 = col2) | ||
joinfun(df1[1:1000, :], df2[1:2000, :], on=:id1) | ||
joinfun(df2[1:2000, :], df1[1:1000, :], on=:id1) | ||
fullgc() | ||
@time joinfun(df1, df2, on=:id1) | ||
fullgc() | ||
@time joinfun(df2, df1, on=:id1) | ||
else | ||
@assert ARGS[6] == "2" | ||
df1 = DataFrame(id1 = col1, id2 = col1) | ||
df2 = DataFrame(id1 = col2, id2 = col2) | ||
joinfun(df1[1:1000, :], df2[1:2000, :], on=[:id1, :id2]) | ||
joinfun(df2[1:2000, :], df1[1:1000, :], on=[:id1, :id2]) | ||
fullgc() | ||
@time joinfun(df1, df2, on=[:id1, :id2]) | ||
fullgc() | ||
@time joinfun(df2, df1, on=[:id1, :id2]) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
julia runtests.jl 100000 50000000 inner | ||
julia runtests.jl 5000000 10000000 inner | ||
julia runtests.jl 100000 50000000 left | ||
julia runtests.jl 5000000 10000000 left | ||
julia runtests.jl 100000 50000000 right | ||
julia runtests.jl 5000000 10000000 right | ||
julia runtests.jl 100000 50000000 outer | ||
julia runtests.jl 5000000 10000000 outer | ||
julia runtests.jl 100000 50000000 semi | ||
julia runtests.jl 5000000 10000000 semi | ||
julia runtests.jl 100000 50000000 anti | ||
julia runtests.jl 5000000 10000000 anti |
File renamed without changes.
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
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
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