-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtractAllLargeChoicesBenchmarks.cs
More file actions
141 lines (119 loc) · 4.93 KB
/
Copy pathExtractAllLargeChoicesBenchmarks.cs
File metadata and controls
141 lines (119 loc) · 4.93 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using BenchmarkDotNet.Attributes;
using Raffinert.FuzzySharp.Extractor;
using Raffinert.FuzzySharp.SimilarityRatio.Scorer;
using Raffinert.FuzzySharp.SimilarityRatio.Scorer.Composite;
using Classic = FuzzySharp;
namespace Raffinert.FuzzySharp.Benchmarks;
[MemoryDiagnoser]
[RankColumn]
public class ExtractAllLargeChoicesBenchmarks
{
private static readonly string[] Teams =
[
"new york mets", "chicago cubs", "new york yankees", "boston red sox", "atlanta braves", "pittsburgh pirates",
"los angeles dodgers", "san francisco giants", "st louis cardinals", "philadelphia phillies", "houston astros",
"texas rangers", "seattle mariners", "san diego padres", "toronto blue jays", "tampa bay rays"
];
private static readonly string[] Venues =
[
"CitiField", "Fenway Park", "PNC Park", "Dodger Stadium", "Oracle Park", "Busch Stadium", "Minute Maid Park", "T-Mobile Park"
];
private static readonly string[] Dates =
[
"2017-03-19", "2017-03-20", "2017-03-21", "2017-03-22", "2017-03-23", "2017-03-24"
];
private static readonly string[] Times =
[
"1pm", "4pm", "7pm", "8pm", "9pm"
];
private ICachedRatioScorer _extractScorer = null!;
private ParallelOptions _parallelOptions = null!;
private string[][] _events = null!;
private string[] _query = null!;
private CachedScorerProcessPipeline _acrossRunsCachedPipeline;
private CachedScorerProcessPipeline _acrossRunsParallelCachedPipeline;
private ProcessPipeline _parallelPipeline;
private ProcessPipeline _cachedPipeline;
private ProcessPipeline _parallelCachedPipeline;
[Params(64, 256, 1024)]
public int ChoiceCount { get; set; }
[GlobalSetup]
public void GlobalSetup()
{
_query = ["new york mets vs chicago cubs game 7 postseason night matchup", "CitiField", "2017-03-19", "8pm"];
_events = BuildEvents(ChoiceCount);
_extractScorer = new CachedWeightedRatioScorer(_query[0]);
_parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
};
_acrossRunsCachedPipeline = Process.Configure()
.Cached(_extractScorer)
.Build();
_acrossRunsParallelCachedPipeline = Process.Configure()
.Cached(_extractScorer)
.Parallel(_parallelOptions)
.Build();
_parallelPipeline = Process.Configure()
.Parallel(_parallelOptions)
.Build();
_cachedPipeline = Process.Configure()
.Cached()
.Build();
_parallelCachedPipeline = Process.Configure()
.Cached()
.Parallel(_parallelOptions)
.Build();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllBy()
{
return Process.ExtractAllBy(_query, _events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<global::FuzzySharp.Extractor.ExtractedResult<string[]>> ExtractAllByClassic()
{
return Classic.Process.ExtractAll(_query, _events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllByParallel()
{
return _parallelPipeline.ExtractAllBy(_query, _events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllByCached()
{
return _cachedPipeline.ExtractAllBy(_query, _events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllByParallelCached()
{
return _parallelCachedPipeline.ExtractAllBy(_query, _events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllByAcrossRunsCached()
{
return _acrossRunsCachedPipeline.ExtractAllBy(_events, static strings => strings[0]).ToList();
}
[Benchmark]
public List<ExtractedResult<string[]>> ExtractAllByAcrossRunsParallelCached()
{
return _acrossRunsParallelCachedPipeline.ExtractAllBy(_events, static strings => strings[0]).ToList();
}
private static string[][] BuildEvents(int count)
{
var events = new string[count][];
for (var i = 0; i < count; i++)
{
var teamA = Teams[i % Teams.Length];
var teamB = Teams[(i * 7 + 3) % Teams.Length];
var venue = Venues[(i * 5 + 1) % Venues.Length];
var date = Dates[(i * 3 + 2) % Dates.Length];
var time = Times[(i * 11 + 4) % Times.Length];
events[i] = [$"{teamA} vs {teamB} regular season series game {(i % 7) + 1}", venue, date, time];
}
events[count / 3] = ["new york mets vs chicago cubs game 7 postseason night matchup", "CitiField", "2017-03-19", "8pm"];
events[(count * 2) / 3] = ["chicago cubs vs new york mets game 7 postseason night matchup", "CitiField", "2017-03-19", "8pm"];
return events;
}
}