56 "Archive/2024/January",
57 "Archive/2024/February",
61 "mailinglists/neomutt-dev",
62 "mailinglists/neomutt-users",
63 "mailinglists/linux-kernel",
64 "mailinglists/debian-devel",
65 "work/projects/libfuzzy",
66 "work/projects/neomutt",
67 "work/reports/weekly",
68 "work/reports/monthly",
72 "notifications/github",
73 "notifications/gitlab",
77 "travel/confirmations",
88#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
90 clock_gettime(CLOCK_MONOTONIC, &ts);
91 return (ts.tv_sec * 1000.0) + (ts.tv_nsec / 1000000.0);
94 return (
double) clock() / CLOCKS_PER_SEC * 1000.0;
106 int iterations,
const char *description)
114 for (
int i = 0; i < iterations; i++)
123 double per_match = elapsed / iterations;
124 double throughput = iterations / (elapsed / 1000.0);
126 printf(
"%-50s ", description);
127 printf(
"%8.2f ms ", elapsed);
128 printf(
"%8.3f µs/op ", per_match * 1000.0);
129 printf(
"%10.0f ops/sec ", throughput);
130 printf(
"(%d/%d matches)\n", matches, iterations);
145 int total_matches = 0;
146 for (
int i = 0; i < iterations; i++)
159 double per_match = elapsed / total_ops;
160 double throughput = total_ops / (elapsed / 1000.0);
162 printf(
"%-50s ",
"Mailbox list search");
163 printf(
"%8.2f ms ", elapsed);
164 printf(
"%8.3f µs/op ", per_match * 1000.0);
165 printf(
"%10.0f ops/sec ", throughput);
166 printf(
"(%d matches in %d ops)\n", total_matches, total_ops);
184 for (
int i = 0; i < iterations; i++)
188 printf(
"%-50s %8.2f ms %8.3f µs/op\n",
" Case-insensitive", elapsed,
189 elapsed / iterations * 1000.0);
197 for (
int i = 0; i < iterations; i++)
201 printf(
"%-50s %8.2f ms %8.3f µs/op\n",
" Case-sensitive", elapsed,
202 elapsed / iterations * 1000.0);
210 for (
int i = 0; i < iterations; i++)
214 printf(
"%-50s %8.2f ms %8.3f µs/op\n",
" Smart case", elapsed,
215 elapsed / iterations * 1000.0);
223 for (
int i = 0; i < iterations; i++)
227 printf(
"%-50s %8.2f ms %8.3f µs/op\n",
" Prefer prefix", elapsed,
228 elapsed / iterations * 1000.0);
238int main(
int argc,
char *argv[])
240 int iterations = 100000;
244 iterations = atoi(argv[1]);
249 if (iterations < 100)
252 printf(
"=================================================================\n");
253 printf(
"libfuzzy Benchmark - %d iterations per test\n", iterations);
254 printf(
"=================================================================\n\n");
256 printf(
"Test Time Per Op Throughput Results\n");
257 printf(
"------------------------------------------------------------------------------------------------------------------------------\n");
260 benchmark_basic(
"box",
"mailbox", iterations,
"Short pattern + short candidate");
264 "Short pattern + medium candidate");
267 benchmark_basic(
"arch",
"Archive/2024/January/Projects/NeoMutt", iterations,
268 "Short pattern + long candidate");
272 iterations,
"Medium pattern + long candidate");
281 benchmark_basic(
"mlnd",
"mailing_list_node_database", iterations,
"Scattered match");
289 printf(
"Realistic Scenario - Searching mailbox list (%d mailboxes)\n",
NUM_MAILBOXES);
290 printf(
"------------------------------------------------------------------------------------------------------------------------------\n");
299 printf(
"Options Comparison\n");
300 printf(
"------------------------------------------------------------------------------------------------------------------------------\n");
305 printf(
"=================================================================\n");
306 printf(
"Benchmark Complete\n");
307 printf(
"=================================================================\n");
int main(int argc, char *argv[])
Entry point for fuzzy benchmark.
static const char * mailbox_paths[]
static void benchmark_mailbox_list(const char *pattern, int iterations)
Benchmark searching through mailbox list.
static void benchmark_basic(const char *pattern, const char *candidate, int iterations, const char *description)
Basic pattern matching benchmark.
static void benchmark_options(const char *pattern, const char *candidate, int iterations)
Benchmark with different options.
static const int NUM_MAILBOXES
static double get_time_ms(void)
Get current time in milliseconds.
bool candidate(struct CompletionData *cd, char *user, const char *src, char *dest, size_t dlen)
Helper function for completion.
@ FUZZY_ALGO_SUBSEQ
Subsequence matching algorithm.
int fuzzy_match(const char *pattern, const char *candidate, enum FuzzyAlgo algo, const struct FuzzyOptions *opts, struct FuzzyResult *out)
Perform fuzzy matching.
Options for fuzzy matching.
int score
Score (<0 = no match)
int start
First match position.
int end
Last match position.