benchmarkGet method
Runs a benchmark for get operations.
The key
parameter is the key to retrieve.
The iterations
parameter is the number of times to run the operation.
The useAsync
parameter determines whether to use the asynchronous get method.
Returns the benchmark result.
Implementation
Future<BenchmarkResult> benchmarkGet({
required String key,
required int iterations,
bool useAsync = false,
}) async {
// First, make sure the key exists
if (!await _cache.containsKey(key)) {
await _cache.put(key, 'benchmark-value');
}
return runBenchmark(
operation: () async {
if (useAsync) {
await _cache.getAsync<dynamic>(key);
} else {
await _cache.get<dynamic>(key);
}
},
iterations: iterations,
name: useAsync ? 'Get (Async)' : 'Get',
);
}