SpecialFunctionsBenchmark#
-
class numpy::SpecialFunctionsBenchmark#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use SpecialFunctionsBenchmark
SpecialFunctionsBenchmark obj;
// ... operations ...
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
const std::vector<BenchmarkResult<T>>& |
NP_SPECIAL_BENCHMARK.H:218 |
|
|
double |
NP_SPECIAL_BENCHMARK.H:59 |
Testing#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_SPECIAL_BENCHMARK.H:241 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
BenchmarkResult<T> |
NP_SPECIAL_BENCHMARK.H:109 |
|
|
void |
NP_SPECIAL_BENCHMARK.H:80 |
|
|
void |
NP_SPECIAL_BENCHMARK.H:225 |
|
|
std::string |
NP_SPECIAL_BENCHMARK.H:158 |
|
|
BenchmarkResult<T> |
NP_SPECIAL_BENCHMARK.H:232 |
|
|
void |
NP_SPECIAL_BENCHMARK.H:138 |
Code Examples#
The following examples are extracted from the test suite.
performance_regression_test (np_test_2_all.cpp:615)
605 if (!(float32_result.results_match)) {
606 std::string description = std::string("testCosinePerformance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(float32_result.results_match)";
607 std::cout << std::string("[FAIL] ") + description << std::endl;
608 throw std::runtime_error(description);
609 }
610 // std::cout << "[OK] Float32 performance test passed\n";
611
612 // Performance regression test
613 SpecialFunctionsBenchmark<double> benchmark;
614 bool regression_passed = benchmark.performance_regression_test(1.5); // Expect at least 1.5x speedup
615
616 if (regression_passed) {
617 // std::cout << "[OK] Performance regression test passed\n";
618 }
619 else {
620 // std::cout << "[INFO] Performance regression test: MKL speedup below threshold\n";
621 }
622
623 std::cout << " -> tests passed\n";
624 }
benchmark_cosine (np_test_2_all.cpp:800)
790 if (!MathBackendConfig::is_mkl_available()) {
791 // std::cout << "[INFO] MKL not available, skipping benchmark reporting test\n";
792 std::cout << " -> tests passed\n";
793 return;
794 }
795
796 // Test benchmark reporting functionality
797 // std::cout << "Testing benchmark report generation...\n";
798
799 SpecialFunctionsBenchmark<double> benchmark;
800 benchmark.benchmark_cosine(10000);
801
802 auto report = benchmark.generate_report();
803 if (!(!report.empty())) {
804 std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!report.empty())";
805 std::cout << std::string("[FAIL] ") + description << std::endl;
806 throw std::runtime_error(description);
807 }
808 if (!(report.find("Special Functions Benchmark Report") != std::string::npos)) {
809 std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"Special Functions Benchmark Report\") != std::string::npos)";
810 std::cout << std::string("[FAIL] ") + description << std::endl;
generate_report (np_test_2_all.cpp:802)
792 std::cout << " -> tests passed\n";
793 return;
794 }
795
796 // Test benchmark reporting functionality
797 // std::cout << "Testing benchmark report generation...\n";
798
799 SpecialFunctionsBenchmark<double> benchmark;
800 benchmark.benchmark_cosine(10000);
801
802 auto report = benchmark.generate_report();
803 if (!(!report.empty())) {
804 std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!report.empty())";
805 std::cout << std::string("[FAIL] ") + description << std::endl;
806 throw std::runtime_error(description);
807 }
808 if (!(report.find("Special Functions Benchmark Report") != std::string::npos)) {
809 std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"Special Functions Benchmark Report\") != std::string::npos)";
810 std::cout << std::string("[FAIL] ") + description << std::endl;
811 throw std::runtime_error(description);
812 }
quick_cosine_benchmark (np_test_2_all.cpp:583)
573 if (!MathBackendConfig::is_mkl_available()) {
574 // std::cout << "[INFO] MKL not available, skipping performance test\n";
575 std::cout << " -> tests passed\n";
576 return;
577 }
578
579 // Run performance benchmark
580 // std::cout << "Running cosine performance benchmark...\n";
581
582 auto float64_result = SpecialFunctionsBenchmark<double>::quick_cosine_benchmark(100000);
583 // std::cout << "Float64 results:\n";
584 // std::cout << " MKL time: " << float64_result.mkl_time_ms << " ms\n";
585 // std::cout << " Std time: " << float64_result.std_time_ms << " ms\n";
586 // std::cout << " Speedup: " << float64_result.speedup << "x\n";
587 // std::cout << " Max error: " << float64_result.max_error << "";
588 // std::cout << " Results match: " << (float64_result.results_match ? "Yes" : "No") << "";
589
590 if (!(float64_result.results_match)) {
591 std::string description = std::string("testCosinePerformance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(float64_result.results_match)";
592 std::cout << std::string("[FAIL] ") + description << std::endl;