SpecialFunctionsBenchmark ========================= .. cpp:class:: numpy::SpecialFunctionsBenchmark numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use SpecialFunctionsBenchmark SpecialFunctionsBenchmark obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``const std::vector>& get_results()`` - const std::vector>& - NP_SPECIAL_BENCHMARK.H:218 - * - ``double get_tolerance()`` - double - NP_SPECIAL_BENCHMARK.H:59 - Testing ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool performance_regression_test(doublemin_expected_speedup = 2.0)`` - bool - NP_SPECIAL_BENCHMARK.H:241 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``BenchmarkResult benchmark_cosine(size_tarray_size)`` - BenchmarkResult - NP_SPECIAL_BENCHMARK.H:109 - :ref:`View ` * - ``void calculate_accuracy(const NDArray&mkl_result, const NDArray&std_result, BenchmarkResult&result)`` - void - NP_SPECIAL_BENCHMARK.H:80 - * - ``void clear_results()`` - void - NP_SPECIAL_BENCHMARK.H:225 - * - ``std::string generate_report()`` - std::string - NP_SPECIAL_BENCHMARK.H:158 - :ref:`View ` * - ``BenchmarkResult quick_cosine_benchmark(size_tarray_size = 100000)`` - BenchmarkResult - NP_SPECIAL_BENCHMARK.H:232 - :ref:`View ` * - ``void run_comprehensive_benchmark()`` - void - NP_SPECIAL_BENCHMARK.H:138 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-specialfunctionsbenchmark-performance_regression_test-0: .. dropdown:: performance_regression_test (np_test_2_all.cpp:615) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 605 :emphasize-lines: 11 if (!(float32_result.results_match)) { std::string description = std::string("testCosinePerformance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(float32_result.results_match)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Float32 performance test passed\n"; // Performance regression test SpecialFunctionsBenchmark benchmark; bool regression_passed = benchmark.performance_regression_test(1.5); // Expect at least 1.5x speedup if (regression_passed) { // std::cout << "[OK] Performance regression test passed\n"; } else { // std::cout << "[INFO] Performance regression test: MKL speedup below threshold\n"; } std::cout << " -> tests passed\n"; } .. _example-specialfunctionsbenchmark-benchmark_cosine-1: .. dropdown:: benchmark_cosine (np_test_2_all.cpp:800) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 790 :emphasize-lines: 11 if (!MathBackendConfig::is_mkl_available()) { // std::cout << "[INFO] MKL not available, skipping benchmark reporting test\n"; std::cout << " -> tests passed\n"; return; } // Test benchmark reporting functionality // std::cout << "Testing benchmark report generation...\n"; SpecialFunctionsBenchmark benchmark; benchmark.benchmark_cosine(10000); auto report = benchmark.generate_report(); if (!(!report.empty())) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!report.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(report.find("Special Functions Benchmark Report") != std::string::npos)) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"Special Functions Benchmark Report\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-specialfunctionsbenchmark-generate_report-2: .. dropdown:: generate_report (np_test_2_all.cpp:802) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 792 :emphasize-lines: 11 std::cout << " -> tests passed\n"; return; } // Test benchmark reporting functionality // std::cout << "Testing benchmark report generation...\n"; SpecialFunctionsBenchmark benchmark; benchmark.benchmark_cosine(10000); auto report = benchmark.generate_report(); if (!(!report.empty())) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!report.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(report.find("Special Functions Benchmark Report") != std::string::npos)) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"Special Functions Benchmark Report\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-specialfunctionsbenchmark-quick_cosine_benchmark-3: .. dropdown:: quick_cosine_benchmark (np_test_2_all.cpp:583) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 573 :emphasize-lines: 11 if (!MathBackendConfig::is_mkl_available()) { // std::cout << "[INFO] MKL not available, skipping performance test\n"; std::cout << " -> tests passed\n"; return; } // Run performance benchmark // std::cout << "Running cosine performance benchmark...\n"; auto float64_result = SpecialFunctionsBenchmark::quick_cosine_benchmark(100000); // std::cout << "Float64 results:\n"; // std::cout << " MKL time: " << float64_result.mkl_time_ms << " ms\n"; // std::cout << " Std time: " << float64_result.std_time_ms << " ms\n"; // std::cout << " Speedup: " << float64_result.speedup << "x\n"; // std::cout << " Max error: " << float64_result.max_error << ""; // std::cout << " Results match: " << (float64_result.results_match ? "Yes" : "No") << ""; if (!(float64_result.results_match)) { std::string description = std::string("testCosinePerformance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(float64_result.results_match)"; std::cout << std::string("[FAIL] ") + description << std::endl;