From d723272cc116f56a415fa8ecc2fb4433f08e5d42 Mon Sep 17 00:00:00 2001 From: dehnert Date: Wed, 11 Dec 2013 10:31:50 +0100 Subject: [PATCH] Added some performance tests for matrix-vector multiplication. Former-commit-id: 521dbf788d097c8d977f75bf148e1ae416f97d4d --- test/performance/storage/SparseMatrixTest.cpp | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/test/performance/storage/SparseMatrixTest.cpp b/test/performance/storage/SparseMatrixTest.cpp index 40a510e36..367bd3401 100644 --- a/test/performance/storage/SparseMatrixTest.cpp +++ b/test/performance/storage/SparseMatrixTest.cpp @@ -22,7 +22,30 @@ TEST(SparseMatrix, Iteration) { } } -TEST(SparseMatrix, Multiplication) { +TEST(SparseMatrix, SparseMultiplication) { + storm::storage::SparseMatrixBuilder matrixBuilder; + for (uint_fast64_t row = 0; row < 100000; ++row) { + ASSERT_NO_THROW(matrixBuilder.addNextValue(row, 0, storm::utility::constantOne())); + ASSERT_NO_THROW(matrixBuilder.addNextValue(row, 1, storm::utility::constantOne())); + } + + storm::storage::SparseMatrix matrix; + ASSERT_NO_THROW(matrix = matrixBuilder.build()); + + std::vector x(matrix.getColumnCount(), 1.0); + std::vector result(matrix.getRowCount()); + + for (uint_fast64_t i = 0; i < 30000; ++i) { + matrix.multiplyWithVector(x, result); + + // The following can never be true, but prevents the compiler from optimizing away the loop. + if (result.size() > matrix.getRowCount()) { + ASSERT_TRUE(false); + } + } +} + +TEST(SparseMatrix, HalfSparseMultiplication) { storm::storage::SparseMatrixBuilder matrixBuilder; for (uint_fast64_t row = 0; row < 2000; ++row) { for (uint_fast64_t column = 0; column < row; ++column) { @@ -39,6 +62,31 @@ TEST(SparseMatrix, Multiplication) { for (uint_fast64_t i = 0; i < 5000; ++i) { matrix.multiplyWithVector(x, result); + // The following can never be true, but prevents the compiler from optimizing away the loop. + if (result.size() > matrix.getRowCount()) { + ASSERT_TRUE(false); + } + } +} + +TEST(SparseMatrix, DenseMultiplication) { + storm::storage::SparseMatrixBuilder matrixBuilder; + uint_fast64_t const size = 2000; + for (uint_fast64_t row = 0; row < size; ++row) { + for (uint_fast64_t column = 0; column < size; ++column) { + ASSERT_NO_THROW(matrixBuilder.addNextValue(row, column, storm::utility::constantOne())); + } + } + + storm::storage::SparseMatrix matrix; + ASSERT_NO_THROW(matrix = matrixBuilder.build()); + + std::vector x(matrix.getColumnCount(), 1.0); + std::vector result(matrix.getRowCount()); + + for (uint_fast64_t i = 0; i < 1000; ++i) { + matrix.multiplyWithVector(x, result); + // The following can never be true, but prevents the compiler from optimizing away the loop. if (result.size() > matrix.getRowCount()) { ASSERT_TRUE(false);