|
1 | 1 | defmodule Bench.HashidsEncode do
|
2 | 2 | use Benchfella
|
3 | 3 |
|
4 |
| - @h_long Hashids.new( |
5 |
| - alphabet: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" <> |
6 |
| - "~!@#$%^&*()_+\"][{}|;:/?.>,<あいうえおかきくけこさしすせそたちつ" <> |
7 |
| - "てとまみむめもらちるれろはひふへほやゆよんをわなにぬねの" <> |
8 |
| - "абвгдежзийклмнопрстуфхцчшщьыъэюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ" |
9 |
| - ) |
10 |
| - |
11 |
| - @h_def Hashids.new() |
12 |
| - |
13 |
| - bench "long alphabet: encode 1" do |
14 |
| - Hashids.encode(@h_long, 1) |
15 |
| - end |
16 |
| - |
17 |
| - bench "long alphabet: encode 100" do |
18 |
| - Hashids.encode(@h_long, 100) |
19 |
| - end |
20 |
| - |
21 |
| - bench "long alphabet: encode 10000" do |
22 |
| - Hashids.encode(@h_long, 10000) |
23 |
| - end |
24 |
| - |
25 |
| - bench "long alphabet: encode a list of 10 integers" do |
26 |
| - Hashids.encode(@h_long, Enum.to_list(1000..1010)) |
27 |
| - end |
28 |
| - |
29 |
| - bench "default alphabet: encode 1" do |
30 |
| - Hashids.encode(@h_def, 1) |
31 |
| - end |
32 |
| - |
33 |
| - bench "default alphabet: encode 100" do |
34 |
| - Hashids.encode(@h_def, 100) |
35 |
| - end |
36 |
| - |
37 |
| - bench "default alphabet: encode 10000" do |
38 |
| - Hashids.encode(@h_def, 10000) |
39 |
| - end |
40 |
| - |
41 |
| - bench "default alphabet: encode a list of 10 integers" do |
42 |
| - Hashids.encode(@h_def, Enum.to_list(1000..1010)) |
| 4 | + hashids = [ |
| 5 | + {"long alphabet", Hashids.new( |
| 6 | + alphabet: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" <> |
| 7 | + "~!@#$%^&*()_+\"][{}|;:/?.>,<あいうえおかきくけこさしすせそたちつ" <> |
| 8 | + "てとまみむめもらちるれろはひふへほやゆよんをわなにぬねの" <> |
| 9 | + "абвгдежзийклмнопрстуфхцчшщьыъэюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ" |
| 10 | + )}, |
| 11 | + {"default alphabet", Hashids.new()} |
| 12 | + ] |
| 13 | + |
| 14 | + for {alpha, h} <- hashids do |
| 15 | + @h h |
| 16 | + bench "#{alpha}: encode 1 integer" do |
| 17 | + Hashids.encode(@h, 100) |
| 18 | + end |
| 19 | + |
| 20 | + bench "#{alpha}: encode 10 integers" do |
| 21 | + Hashids.encode(@h, 1000..1010 |> Enum.to_list) |
| 22 | + end |
| 23 | + |
| 24 | + bench "#{alpha}: encode 100 integers" do |
| 25 | + Hashids.encode(@h, 100..200 |> Enum.to_list) |
| 26 | + end |
43 | 27 | end
|
44 | 28 | end
|
0 commit comments