diff --git a/CMakeLists.txt b/CMakeLists.txt index 3036316d..b39e8db6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,10 @@ if("${BUILD_TESTING}") cxx_acceptance_test_dir "${cxx_test_dir}/acceptance_tests/${PROJECT_NAME}" ) + set( + cxx_performance_test_dir + "${cxx_test_dir}/performance_tests/${PROJECT_NAME}" + ) set(python_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/python") set(python_unit_test_dir "${python_test_dir}/unit_tests") @@ -100,6 +104,13 @@ if("${BUILD_TESTING}") DEPENDS Catch2 ${PROJECT_NAME} ) + cmaize_add_tests( + test_performance_${PROJECT_NAME} + SOURCE_DIR "${cxx_performance_test_dir}" + INCLUDE_DIRS "${project_src_dir}" + DEPENDS Catch2 ${PROJECT_NAME} + ) + cmaize_add_tests( acceptance_test_${PROJECT_NAME} SOURCE_DIR "${cxx_acceptance_test_dir}" diff --git a/tests/cxx/performance_tests/tensorwrapper/contraction.cpp b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp new file mode 100644 index 00000000..4124b6f4 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/contraction.cpp @@ -0,0 +1,37 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "performance_testing.hpp" +#include +#include + +using namespace tensorwrapper; + +TEST_CASE("Contraction") { + Tensor A{1.0, 2.0, 3.0}; + Tensor B{4.0, 5.0, 6.0}; + Tensor C; + + auto l = [&A, &B, &C]() { + C("") = A("i") * B("i"); + return C; + }; + + parallelzone::hardware::CPU cpu; + auto [rv, info] = cpu.profile_it(std::move(l)); + + std::cout << "Time in ns: " << info.wall_time.count() << std::endl; +} \ No newline at end of file diff --git a/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp b/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp new file mode 100644 index 00000000..456683b3 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/performance_testing.hpp @@ -0,0 +1,22 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/tests/cxx/performance_tests/tensorwrapper/test_main.cpp b/tests/cxx/performance_tests/tensorwrapper/test_main.cpp new file mode 100644 index 00000000..030cf950 --- /dev/null +++ b/tests/cxx/performance_tests/tensorwrapper/test_main.cpp @@ -0,0 +1,27 @@ +/* + * Copyright 2024 NWChemEx Community + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CATCH_CONFIG_RUNNER +#include +#include + +int main(int argc, char* argv[]) { + auto rt = parallelzone::runtime::RuntimeView(argc, argv); + + int res = Catch::Session().run(argc, argv); + + return res; +}