Skip to content

Commit 35a3483

Browse files
committed
benchmarks
1 parent e784e61 commit 35a3483

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*.csv
66

77
*.png
8+
!readme_string_sort.png

benchmarks/benchmarks.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ end
3434

3535
string_sort_perf(100, 100) # warm up
3636

37-
@time string_sort_perf.((1:10).*10^8, 100)
37+
@time string_sort_perf.((1:10).*10^8, 100)
38+

benchmarks/readme.jl

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# short be
2+
using SortingLab, ShortStrings, SortingAlgorithms, BenchmarkTools;
3+
N = Int(1e6);
4+
svec = [randstring(rand(1:15)) for i=1:N];
5+
# convert to ShortString
6+
ssvec = ShortString.(svec);
7+
basesort = @benchmark sort($svec)
8+
radixsort_timings = @benchmark SortingLab.radixsort($svec)
9+
short_radixsort = @benchmark sort($ssvec, by = x->x.size_content, alg=RadixSort)
10+
11+
using RCall
12+
13+
@rput svec;
14+
r_timings = R"""
15+
replicate($(length(short_radixsort.times)), system.time(sort(svec, method="radix"))[3])
16+
""";
17+
18+
using Plots
19+
bar(["Base.sort","SortingLab.radixsort","ShortStrings radix sort", "R radix sort"],
20+
mean.([basesort.times./1e9, radixsort_timings.times./1e9, short_radixsort.times./1e9, r_timings]),
21+
title="String sort performance - len: 1m, variable size 15",
22+
label = "seconds")
23+
savefig("readme_string_sort.png")

readme_string_sort.png

69 KB
Loading

src/ShortStrings.jl

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Base.display(s::ShortString) = display(s.size_content)
2929
Base.convert(::ShortString, s::String) = ShortString(s)
3030
Base.convert(::String, ss::ShortString) = reduce(*, ss)
3131
Base.start(::ShortString) = 1
32+
# Base.sort(svec::AbstractVector{ShortString}; rev::Bool = false) = sort(svec, rev=rev, by = x->x.size_content, alg=RadixSort)
3233
# Base.sort(x::AbstractVector{ShortString}; kwargs...) = sort(x, by = x->x.size_content, alg = RadixSort; kwargs...)
3334

3435
end # module
36+
37+

0 commit comments

Comments
 (0)