[libc-commits] [libc] a09c0f6 - [libc] Add Minimum Time and Iterations, Reduce Epsilon (#100838)

via libc-commits libc-commits at lists.llvm.org
Fri Jul 26 18:30:23 PDT 2024


Author: jameshu15869
Date: 2024-07-26T20:30:19-05:00
New Revision: a09c0f676d3c61ba8f74a24172543c1e44d70628

URL: https://github.com/llvm/llvm-project/commit/a09c0f676d3c61ba8f74a24172543c1e44d70628
DIFF: https://github.com/llvm/llvm-project/commit/a09c0f676d3c61ba8f74a24172543c1e44d70628.diff

LOG: [libc] Add Minimum Time and Iterations, Reduce Epsilon (#100838)

This PR adds minimums (50 iterations, 500 us, and epsilon of 0.0001) to
ensure that all benchmarks run at least a set number of times before
outputting a final measurement.

Added: 
    

Modified: 
    libc/benchmarks/gpu/LibcGpuBenchmark.cpp
    libc/benchmarks/gpu/LibcGpuBenchmark.h

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/gpu/LibcGpuBenchmark.cpp b/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
index 031ad163c20da..a9a912538cd84 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
+++ b/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
@@ -205,6 +205,7 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
     if (samples >= options.max_samples || iterations >= options.max_iterations)
       break;
     if (total_time >= options.min_duration && samples >= options.min_samples &&
+        total_iterations >= options.min_iterations &&
         change_ratio < options.epsilon)
       break;
 

diff  --git a/libc/benchmarks/gpu/LibcGpuBenchmark.h b/libc/benchmarks/gpu/LibcGpuBenchmark.h
index f5cf4822f6fd3..ca5ad8a595d54 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmark.h
+++ b/libc/benchmarks/gpu/LibcGpuBenchmark.h
@@ -17,12 +17,13 @@ namespace benchmarks {
 
 struct BenchmarkOptions {
   uint32_t initial_iterations = 1;
+  uint32_t min_iterations = 50;
   uint32_t max_iterations = 10000000;
   uint32_t min_samples = 4;
   uint32_t max_samples = 1000;
-  int64_t min_duration = 0;                  // in nanoseconds (ns)
+  int64_t min_duration = 500 * 1000;         // 500 * 1000 nanoseconds = 500 us
   int64_t max_duration = 1000 * 1000 * 1000; // 1e9 nanoseconds = 1 second
-  double epsilon = 0.01;
+  double epsilon = 0.0001;
   double scaling_factor = 1.4;
 };
 


        


More information about the libc-commits mailing list