-
-
Save zachmatson/eee359f97e8654bebf75aad43a0e3d6e to your computer and use it in GitHub Desktop.
ArgMacros 0.2.0 vs ArgParse 1.1.0
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
using ArgMacros | |
let | |
args = @dictarguments begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
println( | |
args[:a] * | |
args[:b] + | |
(something(args[:c], :c) |> String |> length) + | |
args[:d] + | |
args[:e] + | |
(args[:f] |> length) + | |
args[:g] * | |
something(args[:h], 5) | |
) | |
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
using ArgMacros | |
function consume_args(args) | |
println( | |
args[:a] * | |
args[:b] + | |
(something(args[:c], :c) |> String |> length) + | |
args[:d] + | |
args[:e] + | |
(args[:f] |> length) + | |
args[:g] * | |
something(args[:h], 5) | |
) | |
end | |
let | |
args = @dictarguments begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
consume_args(args) | |
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
using ArgMacros | |
let | |
@inlinearguments begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
println( | |
a * | |
b + | |
(something(c, :c) |> String |> length) + | |
d + | |
e + | |
(f |> length) + | |
g * | |
something(h, 5) | |
) | |
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
using ArgMacros | |
@structarguments false Args begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
let | |
args = Args() | |
println( | |
args.a * | |
args.b + | |
(something(args.c, :c) |> String |> length) + | |
args.d + | |
args.e + | |
(args.f |> length) + | |
args.g * | |
something(args.h, 5) | |
) | |
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
using ArgMacros | |
@structarguments false Args begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
function consume_args(args::Args) | |
println( | |
args.a * | |
args.b + | |
(something(args.c, :c) |> String |> length) + | |
args.d + | |
args.e + | |
(args.f |> length) + | |
args.g * | |
something(args.h, 5) | |
) | |
end | |
let | |
args = Args() | |
consume_args(args) | |
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
using ArgMacros | |
let | |
args = @tuplearguments begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
println( | |
args.a * | |
args.b + | |
(something(args.c, :c) |> String |> length) + | |
args.d + | |
args.e + | |
(args.f |> length) + | |
args.g * | |
something(args.h, 5) | |
) | |
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
using ArgMacros | |
function consume_args(args) | |
println( | |
args.a * | |
args.b + | |
(something(args.c, :c) |> String |> length) + | |
args.d + | |
args.e + | |
(args.f |> length) + | |
args.g * | |
something(args.h, 5) | |
) | |
end | |
let | |
args = @tuplearguments begin | |
@argumentrequired Int a "-a" "--aa" | |
@argumentdefault Float64 10 b "-b" | |
@argumentoptional Symbol c "--cc" | |
@argumentflag d "-d" | |
@argumentcount e "-e" | |
@positionalrequired String f | |
@positionaldefault Int 20 g | |
@argtest g (x -> x % 10 == 0) | |
@positionaloptional Float64 h | |
end | |
consume_args(args) | |
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
using ArgParse | |
let | |
s = ArgParseSettings() | |
@add_arg_table s begin | |
"-a", "--aa" | |
arg_type = Int | |
required = true | |
"-b" | |
arg_type = Float64 | |
default = 10.0 | |
"--cc" | |
arg_type = Symbol | |
"-d" | |
action = :store_true | |
"-e" | |
action = :count_invocations | |
"f" | |
arg_type = String | |
required = true | |
"g" | |
arg_type = Int | |
default = 20 | |
range_tester = (x -> x % 10 == 0) | |
"h" | |
arg_type = Float64 | |
end | |
args = parse_args(ARGS, s, as_symbols = true) | |
println( | |
args[:aa] * | |
args[:b] + | |
(something(args[:cc], :c) |> String |> length) + | |
args[:d] + | |
args[:e] + | |
(args[:f] |> length) + | |
args[:g] * | |
something(args[:h], 5) | |
) | |
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
using ArgParse | |
function consume_args(args) | |
println( | |
args[:aa] * | |
args[:b] + | |
(something(args[:cc], :c) |> String |> length) + | |
args[:d] + | |
args[:e] + | |
(args[:f] |> length) + | |
args[:g] * | |
something(args[:h], 5) | |
) | |
end | |
let | |
s = ArgParseSettings() | |
@add_arg_table s begin | |
"-a", "--aa" | |
arg_type = Int | |
required = true | |
"-b" | |
arg_type = Float64 | |
default = 10.0 | |
"--cc" | |
arg_type = Symbol | |
"-d" | |
action = :store_true | |
"-e" | |
action = :count_invocations | |
"f" | |
arg_type = String | |
required = true | |
"g" | |
arg_type = Int | |
default = 20 | |
range_tester = (x -> x % 10 == 0) | |
"h" | |
arg_type = Float64 | |
end | |
args = parse_args(ARGS, s, as_symbols = true) | |
consume_args(args) | |
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
# This file is machine-generated - editing it directly is not advised | |
[[ArgParse]] | |
deps = ["Logging", "TextWrap"] | |
git-tree-sha1 = "a8fc2e149cd6db276c76faebe197ccd3a92fb9ff" | |
uuid = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" | |
version = "1.1.0" | |
[[Logging]] | |
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | |
[[TextWrap]] | |
git-tree-sha1 = "9250ef9b01b66667380cf3275b3f7488d0e25faf" | |
uuid = "b718987f-49a8-5099-9789-dcd902bef87d" | |
version = "1.0.1" |
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
[deps] | |
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" |
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
echo Comparison of argument parsers in julia | |
echo | |
echo "All inputs test (all computations in main function with args retrieval)" | |
echo "time julia --project benchmark_foo.jl -- \"TEST STRING F\" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2" | |
echo Expected output 133.76 for all scripts | |
echo | |
echo "ArgMacros (inline)" | |
time julia --project benchmark_ArgMacros_inline.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "ArgMacros (struct)" | |
time julia --project benchmark_ArgMacros_struct.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "ArgMacros (tuple)" | |
time julia --project benchmark_ArgMacros_tuple.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "ArgMacros (dict)" | |
time julia --project benchmark_ArgMacros_dict.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo ArgParse | |
time julia --project benchmark_ArgParse.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "All inputs test (args passed to separate function as single object)" | |
echo "time julia --project benchmark_foo.jl -- \"TEST STRING F\" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2" | |
echo Expected output 133.76 for all scripts | |
echo | |
echo "ArgMacros (inline)" | |
echo "N/A" | |
echo | |
echo "ArgMacros (struct)" | |
time julia --project benchmark_ArgMacros_struct_separate_function.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "ArgMacros (tuple)" | |
time julia --project benchmark_ArgMacros_tuple_separate_function.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "ArgMacros (dict)" | |
time julia --project benchmark_ArgMacros_dict_separate_function.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo ArgParse | |
time julia --project benchmark_ArgParse_separate_function.jl -- "TEST STRING F" -deeee 30 3.14 -b=6.28 --cc ArgMacros -a 2 | |
echo | |
echo "Minimal inputs test (all computations in main function with args retrieval)" | |
echo "time julia --project benchmark_foo.jl -- \"OTHER TEST STRING F\" --aa=5" | |
echo Expected output 170.0 for all scripts | |
echo | |
echo "ArgMacros (inline)" | |
time julia --project benchmark_ArgMacros_inline.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "ArgMacros (struct)" | |
time julia --project benchmark_ArgMacros_struct.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "ArgMacros (tuple)" | |
time julia --project benchmark_ArgMacros_tuple.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "ArgMacros (dict)" | |
time julia --project benchmark_ArgMacros_dict.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo ArgParse | |
time julia --project benchmark_ArgParse.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "Minimal inputs test (args passed to separate function as single object)" | |
echo "time julia --project benchmark_foo.jl -- \"OTHER TEST STRING F\" --aa=5" | |
echo Expected output 170.0 for all scripts | |
echo | |
echo "ArgMacros (inline)" | |
echo "N/A" | |
echo | |
echo "ArgMacros (struct)" | |
time julia --project benchmark_ArgMacros_struct_separate_function.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "ArgMacros (tuple)" | |
time julia --project benchmark_ArgMacros_tuple_separate_function.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo "ArgMacros (dict)" | |
time julia --project benchmark_ArgMacros_dict_separate_function.jl -- "OTHER TEST STRING F" --aa=5 | |
echo | |
echo ArgParse | |
time julia --project benchmark_ArgParse_separate_function.jl -- "OTHER TEST STRING F" --aa=5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment