benchmarkPut method
Future<BenchmarkResult>
benchmarkPut({
- required String keyPrefix,
- required dynamic value,
- required int iterations,
- CachePolicy? policy,
- bool useAsync = false,
Runs a benchmark for put operations.
The keyPrefix
parameter is the prefix for the keys.
The value
parameter is the value to store.
The iterations
parameter is the number of times to run the operation.
The policy
parameter is the cache policy to use.
The useAsync
parameter determines whether to use the asynchronous put method.
Returns the benchmark result.
Implementation
Future<BenchmarkResult> benchmarkPut({
required String keyPrefix,
required dynamic value,
required int iterations,
CachePolicy? policy,
bool useAsync = false,
}) async {
return runBenchmark(
operation: () async {
final key = '$keyPrefix-${DateTime.now().microsecondsSinceEpoch}';
if (useAsync) {
await _cache.putAsync(key, value, policy: policy);
} else {
await _cache.put(key, value, policy: policy);
}
},
iterations: iterations,
name: useAsync ? 'Put (Async)' : 'Put',
);
}