-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcstrings.jl
51 lines (45 loc) · 1.41 KB
/
cstrings.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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