MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / benchmark_function

Function benchmark_function

tests/test-quantize-perf.cpp:79–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79static void benchmark_function(size_t size, size_t q_size, int64_t iterations, const std::function<float(void)> & func) {
80 int64_t min_time_us = INT64_MAX;
81 int64_t total_time_us = 0;
82 int64_t min_time_cycles = INT64_MAX;
83 int64_t total_time_cycles = 0;
84
85 for (int i = 0; i < WARMUP; i++) {
86 func();
87 }
88
89 for (int i = 0; i < iterations; i++) {
90 const int64_t start_time = ggml_time_us();
91 const int64_t start_cycles = cpu_cycles();
92
93 func();
94
95 const int64_t end_cycles = cpu_cycles();
96 const int64_t end_time = ggml_time_us();
97
98 total_time_cycles += end_cycles - start_cycles;
99 min_time_cycles = std::min(min_time_cycles, end_cycles - start_cycles);
100 total_time_us += end_time - start_time;
101 min_time_us = std::min(min_time_us, end_time - start_time);
102 }
103
104 printf(" min cycles/%d vals : %9.2f\n", QK, QK * min_time_cycles / (float) size);
105 printf(" avg cycles/%d vals : %9.2f\n", QK, QK * total_time_cycles / (float) (size * iterations));
106 printf(" float32 throughput : %9.2f GB/s\n", gigabytes_per_second(4 * size * iterations, total_time_us));
107 printf(" quantized throughput : %9.2f GB/s\n", gigabytes_per_second(q_size * iterations, total_time_us));
108}
109
110static void usage(char * argv[]) {
111 printf("Benchmark quantization specific functions on synthetic data\n");

Callers 1

mainFunction · 0.70

Calls 5

minFunction · 0.85
printfFunction · 0.85
cpu_cyclesFunction · 0.70
gigabytes_per_secondFunction · 0.70
ggml_time_usFunction · 0.50

Tested by

no test coverage detected