Skip to content

Commit

Permalink
[julia/bench_cstrings] benchmarks for JuliaLang/julia#15773
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Apr 6, 2016
1 parent 1a9ee20 commit f869932
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions julia/bench_cstrings/cstrings.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/julia -f

using Benchmarks

function show_benchmark_result(r)
stats = Benchmarks.SummaryStatistics(r)
max_length = 24
if isnull(stats.elapsed_time_lower) || isnull(stats.elapsed_time_upper)
@printf("%s: %s\n",
Benchmarks.lpad("Time per evaluation", max_length),
Benchmarks.pretty_time_string(stats.elapsed_time_center))
else
@printf("%s: %s [%s, %s]\n",
Benchmarks.lpad("Time per evaluation", max_length),
Benchmarks.pretty_time_string(stats.elapsed_time_center),
Benchmarks.pretty_time_string(get(stats.elapsed_time_lower)),
Benchmarks.pretty_time_string(get(stats.elapsed_time_upper)))
end
end

macro show_benchmark(ex)
quote
println($(QuoteNode(ex)))
show_benchmark_result(@benchmark $(esc(ex)))
end
end

ascii_strs = ["0123"^i for i in (1, 10, 100, 1000)]
utf8_strs = ["αβγδ"^i for i in (1, 10, 100, 1000)]

println("ASCII:")
for s in ascii_strs
sp = pointer(s)
print(length(s), " ")
@show_benchmark utf8(sp)
print(length(s), " ")
@show_benchmark utf8(sp, 4)
print(length(s), " ")
@show_benchmark ascii(sp)
print(length(s), " ")
@show_benchmark ascii(sp, 4)
end

println("UTF8:")
for s in utf8_strs
sp = pointer(s)
print(length(s), " ")
@show_benchmark utf8(sp)
print(length(s), " ")
@show_benchmark utf8(sp, 8)
end

0 comments on commit f869932

Please sign in to comment.