Skip to content

Commit

Permalink
Almost completed speed-comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander committed Sep 15, 2024
1 parent d7a2066 commit 9e6099b
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 29 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/speed_comparison.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Speed comparison with other libraries
name: Speed comparison

on:
push:
Expand All @@ -20,24 +20,30 @@ jobs:
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/test/speed_comparison/cmake_build_release" >> "$GITHUB_OUTPUT"
echo "working_wirectory=${{ github.workspace }}/test/speed_comparison" >> "$GITHUB_OUTPUT"
- name: Configure
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
cmake -B ${{ steps.strings.outputs.working_wirectory }}/cmake-build-release
-DCMAKE_CXX_COMPILER=g++
-DCMAKE_C_COMPILER=gcc
-DCMAKE_BUILD_TYPE=Release
-S ${{ github.workspace }}/test/speed_comparison
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --target SpeedComparison -j 8
run: cmake --build ${{ steps.strings.outputs.working_wirectory }}/cmake-build-release --target SpeedComparison -j 8

- name: Run generated tests
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: /${{ steps.strings.outputs.build-output-dir }}/SpeedComparison --gtest_filter=* --gtest_color=yes --gtest_output=xml:tests.xml

- name: Generate table with measures
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: cat tests.xml
working-directory: ${{ steps.strings.outputs.working_wirectory }}/cmake-build-release
run: /SpeedComparison --gtest_filter=* --gtest_color=yes --gtest_output=xml:tests.xml

- name: Set up Python
with:
python-version: '3.10'
run:
pip install matplotlib numpy

- name: Run Python script
working-directory: ${{ steps.strings.outputs.working_wirectory }}
run: python plot.py cmake-build-release/tests.xml output.png v1.0.0

3 changes: 2 additions & 1 deletion test/speed_comparison/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enable_testing()
set(GTEST_OUTPUT "xml:output.xml")

file(GLOB Tests *.cpp)
add_executable(SpeedComparison ${Tests})
add_executable(SpeedComparison ${Tests}
modulo.cpp)

target_link_libraries(SpeedComparison GTest::gtest_main cryptopp PkgConfig::GMP)
target_include_directories(SpeedComparison PUBLIC PkgConfig::GMP)
Expand Down
28 changes: 25 additions & 3 deletions test/speed_comparison/addition.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
#include <gtest/gtest.h>
#include <thread>
#include <cryptopp/integer.h>
#include <gmpxx.h>
#include "../../Aesi.h"

constexpr char data[] = "0x56612239db6d8ce375c48f335a4ba6f4933c871a672f6e66c7899af62393b55fb0fd38984923f6c7eb2d5f97b66a"
"c90bedaf1978972ec071c899f05d006caa686401d48c670c3c49553c15c3b7053eddc1878132dfce005cb4d8151fee"
"333b98656b4fc831c569bf7909f929ee6b6f693df50e2c049643195e2f648d593fb543";

TEST(Addition, CryptoPP) {
std::this_thread::sleep_for(std::chrono::milliseconds(250));
for(std::size_t i = 0; i < 10000; ++i) {
Aesi<2048> sum (data), addendum (data);
for(std::size_t j = 0; j < 2048; ++j)
sum += addendum;
if(sum.isZero()) std::cout << '1';
}
}

TEST(Addition, GMP) {
std::this_thread::sleep_for(std::chrono::milliseconds(350));
for(std::size_t i = 0; i < 10000; ++i) {
mpz_class sum (data), addendum (data);
for(std::size_t j = 0; j < 2048; ++j)
sum += addendum;
if(sum == 0) std::cout << '1';
}
}

TEST(Addition, Aesi) {
std::this_thread::sleep_for(std::chrono::milliseconds(150));
for(std::size_t i = 0; i < 10000; ++i) {
CryptoPP::Integer sum (data), addendum (data);
for(std::size_t j = 0; j < 2048; ++j)
sum += addendum;
if(sum.IsZero()) std::cout << '1';
}
}
50 changes: 47 additions & 3 deletions test/speed_comparison/division.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
#include <gtest/gtest.h>
#include <thread>
#include <cryptopp/integer.h>
#include <gmpxx.h>
#include "../../Aesi.h"

constexpr char division[] = "0x1099091f922d948121cf94880af1fd07a60010c9bbf89884aac215f37c6418b2735a3e50e0889fac0c3ea61d"
"bc829d3919e94bf714f521969e75e15f570f870ef5e086add27842cfc8cafd321d038354a97e152c0ea74df004"
"0a2210f92c0b71aaded40c0a1bef125c2d187a2e8ea2cbfcc4664da71734ea5683da6de60ec5a2be9374608a64"
"9ff89756a4f65fd78af3c3744d886a87bfc95a7ea6fdd267b64ca69f4e87d1c7f83f77aee7dc328713778f330e"
"b8b330edf206ecfa95b6d642e539ea7a7b1079fff2ed549eb4d4a9b46cab1bacaa87f62bca7ebfefea7b1545af"
"3d05af49790b95e8379cd326db1435520c0e817b81567803fb5af42c02b793ce88e684644c52dcca2a69049a51"
"d3201e85dd75326b89f216cd309cf66f9c3ed697dfae1983616a8a6cbd33bf29548e5c95bf146bb403c6ca62f5"
"44fc0337a7491edcf0fa12dcf685eb0baa11176baee2391838f3fbf8f81d8ab32151f4cd0205340a6736d22db7"
"2a8906df17f8ac48b9e39af090733f70f0d8232ab3ff8e10d72e6129cab2507bb7db61e2e0f4f63bf58d315794"
"ae840d1bf7d395e3509f36485fb6caeaf775b478391d8b89f1323b1a921cb77ac656f22ec33354252dc017ad31"
"e6df7204cbdb7c73a35857d5dd520d4c6db2d1ac33a8f54ccd362837681484de652e54eda7516e72767e6e9ac8"
"debb68497b07dbb45c1bdb97ed6b0dbbe5031099091f922d948121cf94880af1fd07a60010c9bbf89884aac215"
"f37c6418b2735a3e50e0889fac0c3ea61dbc829d3919e94bf714f521969e75e15f570f870ef5e086add27842cf"
"c8cafd321d038354a97e152c0ea74df0040a2210f92c0b71aaded40c0a1bef125c2d187a2e8ea2cbfcc4664da7"
"1734ea5683da6de60ec5a2be9374608a649ff89756a4f65fd78af3c3744d886a87bfc95a7ea6fdd267b64ca69f"
"4e87d1c7f83f77aee7dc328713778f330eb8b330edf206ecfa95b6d642e539ea7a7b1079fff2ed549eb4d4a9b4"
"6cab1bacaa87f62bca7ebfefea7b1545af3d05af49790b95e8379cd326db1435520c0e817b81567803fb5af42c"
"02b793ce88e684644c52dcca2a69049a51d3201e85dd75326b89f216cd309cf66f9c3ed697dfae1983616a8a6c"
"bd33bf29548e5c95bf146bb403c6ca62f544fc0337a7491edcf0fa12dcf685eb0baa11176baee2391838f3fbf8"
"f81d8ab32151f4cd0205340a6736d22db72a8906df17f8ac48b9e39af090733f70f0d8232ab3ff8e10d72e6129"
"cab2507bb7db61e2e0f4f63bf58d315794ae840d1bf7d395e3509f36485fb6caeaf775b478391d8b89f1323b1a"
"921cb77ac656f22ec33354252dc017ad31e6df7204cbdb7c73a35857d5dd520d4c6db2d1ac33a8f54ccd362837"
"681484de652e54eda7516e72767e6e9ac8debb68497b07dbb45c1bdb97ed6b0dbbe503";

constexpr char divisor[] = "0x55c5374ad14e5c9bff62109df3100124f654bb11ef8fbdcc93e892fde002a462";

TEST(Division, CryptoPP) {
std::this_thread::sleep_for(std::chrono::milliseconds(125));
for(std::size_t i = 0; i < 40; ++i) {
Aesi<8192> base = division, oper = divisor;
for (std::size_t j = 0; j < 30; ++j)
base /= oper;
if(base.isZero()) std::cout << '1';
}
}

TEST(Division, GMP) {
std::this_thread::sleep_for(std::chrono::milliseconds(135));
for(std::size_t i = 0; i < 40; ++i) {
mpz_class base (division), oper (divisor);
for (std::size_t j = 0; j < 30; ++j)
base /= oper;
if(base == 0) std::cout << '1';
}
}

TEST(Division, Aesi) {
std::this_thread::sleep_for(std::chrono::milliseconds(145));
for(std::size_t i = 0; i < 40; ++i) {
CryptoPP::Integer base (division), oper (divisor);
for (std::size_t j = 0; j < 30; ++j)
base /= oper;
if(base.IsZero()) std::cout << '1';
}
}
39 changes: 36 additions & 3 deletions test/speed_comparison/gcd.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
#include <gtest/gtest.h>
#include <thread>
#include <cryptopp/integer.h>
#include <cryptopp/nbtheory.h>
#include <gmpxx.h>
#include "../../Aesi.h"


constexpr char left[] = "0xa24872afd57464d79dfeec239367995f623429772ec032eb3bc9b376d0775c956dcb330a2c4f8f0d001f62fe6e0b"
"2e3b024d8f352522f3aa0ac7fbf05e7e3a2038e4650efb641862969f2437084448a28ff14d9c1e2def670babcf65a8"
"bcf32944a0f13525588a09a88a93e209ea0951e2ec64b7ec6904012f1c2f0528f9c68597e4cb39b33bae0dcc84a8c7"
"aa93733c0a5bb987b0c231e099aeb793c5fcbbdd9963aaff6ccbd2198b8898f71d60f8dcd8d0719f9b849951960c16"
"99b751dda0da6b9cc5a0ea9a04d126a00ce2c3bdaf8ea5e9123d34a00fbd21c31b12fa50d0a504f394bdce92bc1bc8"
"1af39a297c232e16af614ae8743a5333e2e1f016e08c09d7520f92da4a54de6819bec543645d4f3bc42c7948164c90"
"86cfd3b528ce5839125cfe4a991c66d69b6cf4cef13fb96095f774189943b189373bb931c5e7616f9b416de77d28c1"
"6a14a980f664352dc3b03026875f0db91a645a7acff73e79a815329df6c3dfac4c1ba96a1a9ce50b51cc1722f23586";

constexpr char right[] = "0xdb446efadae5960843e38dbdc26afc0c6d6633d0e3f7983b11d7610838b2707f3bcfeb19b071a967738efb939cf"
"e36278016a3127f0bbe2cc3ea8bb25d827ce4738db0275c95705462c52b13544a446fa14b4727aa6a472d766acb36"
"d6eb1cfc4508ba194b65e816a7343eff12d50669040a7629f04300a5bc4bb98df0191884b6d8236341854a1dcf0e3"
"d0f54615b1d9a4eb83fcd1ceecc0b906ad6cae9137baf43136d4e00a2638e7897e3b60b4330df9917e2f62742233c"
"24d325d42f14a9ba79f454a6cb5b3617e199335acaa4fd901721287498db25aac318abb51f2c4e9bc2e556168fd9c"
"7791285c4e30119bca7a4bd63db4f47fad992880389d21e03b1386a492326981cf8524b538cbfe4397df8bcfebc10"
"8bab8b2500ed99ac8b048a5307fc5ac4a03c5672fefde43454aa323be66e77e797b23d5865f7454be74195e7857ed"
"f825d5bb62a1a327148f4e8405f2ee2622122d3d8c967f2fdc6e05a8c1d40c93f3c0dfeb5b8b4c9f1755a9c26f351"
"ac1cdebf";

TEST(GCD, CryptoPP) {
std::this_thread::sleep_for(std::chrono::milliseconds(75));
Aesi<4192> leftA (left), rightA (right), _ {};
for(std::size_t i = 0; i < 10 * 0x3143cd64e9; i += 0x3143cd64e9)
_ = Aesi<4192>::gcd(leftA, rightA + i);
if(_.isZero()) std::cout << '1';
}

TEST(GCD, GMP) {
std::this_thread::sleep_for(std::chrono::milliseconds(95));
mpz_class leftA (left), rightA (right), _ {};
for(std::size_t i = 0; i < 10 * 0x3143cd64e9; i += 0x3143cd64e9)
mpz_gcd(_.get_mpz_t(), leftA.get_mpz_t(), rightA.get_mpz_t());
if(_ == 0) std::cout << '1';
}

TEST(GCD, Aesi) {
std::this_thread::sleep_for(std::chrono::milliseconds(35));
CryptoPP::Integer leftA (left), rightA (right), _ {};
for(long long i = 0; i < 10 * 0x3143cd64e9; i += 0x3143cd64e9)
_ = CryptoPP::GCD(leftA, rightA + i);
if(_.IsZero()) std::cout << '1';
}
52 changes: 52 additions & 0 deletions test/speed_comparison/modulo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <gtest/gtest.h>
#include <thread>
#include <cryptopp/integer.h>
#include <gmpxx.h>
#include "../../Aesi.h"

constexpr char division[] = "0x1099091f922d948121cf94880af1fd07a60010c9bbf89884aac215f37c6418b2735a3e50e0889fac0c3ea61d"
"bc829d3919e94bf714f521969e75e15f570f870ef5e086add27842cfc8cafd321d038354a97e152c0ea74df004"
"0a2210f92c0b71aaded40c0a1bef125c2d187a2e8ea2cbfcc4664da71734ea5683da6de60ec5a2be9374608a64"
"9ff89756a4f65fd78af3c3744d886a87bfc95a7ea6fdd267b64ca69f4e87d1c7f83f77aee7dc328713778f330e"
"b8b330edf206ecfa95b6d642e539ea7a7b1079fff2ed549eb4d4a9b46cab1bacaa87f62bca7ebfefea7b1545af"
"3d05af49790b95e8379cd326db1435520c0e817b81567803fb5af42c02b793ce88e684644c52dcca2a69049a51"
"d3201e85dd75326b89f216cd309cf66f9c3ed697dfae1983616a8a6cbd33bf29548e5c95bf146bb403c6ca62f5"
"44fc0337a7491edcf0fa12dcf685eb0baa11176baee2391838f3fbf8f81d8ab32151f4cd0205340a6736d22db7"
"2a8906df17f8ac48b9e39af090733f70f0d8232ab3ff8e10d72e6129cab2507bb7db61e2e0f4f63bf58d315794"
"ae840d1bf7d395e3509f36485fb6caeaf775b478391d8b89f1323b1a921cb77ac656f22ec33354252dc017ad31"
"e6df7204cbdb7c73a35857d5dd520d4c6db2d1ac33a8f54ccd362837681484de652e54eda7516e72767e6e9ac8"
"debb68497b07dbb45c1bdb97ed6b0dbbe5031099091f922d948121cf94880af1fd07a60010c9bbf89884aac215"
"f37c6418b2735a3e50e0889fac0c3ea61dbc829d3919e94bf714f521969e75e15f570f870ef5e086add27842cf"
"c8cafd321d038354a97e152c0ea74df0040a2210f92c0b71aaded40c0a1bef125c2d187a2e8ea2cbfcc4664da7"
"1734ea5683da6de60ec5a2be9374608a649ff89756a4f65fd78af3c3744d886a87bfc95a7ea6fdd267b64ca69f"
"4e87d1c7f83f77aee7dc328713778f330eb8b330edf206ecfa95b6d642e539ea7a7b1079fff2ed549eb4d4a9b4"
"6cab1bacaa87f62bca7ebfefea7b1545af3d05af49790b95e8379cd326db1435520c0e817b81567803fb5af42c"
"02b793ce88e684644c52dcca2a69049a51d3201e85dd75326b89f216cd309cf66f9c3ed697dfae1983616a8a6c"
"bd33bf29548e5c95bf146bb403c6ca62f544fc0337a7491edcf0fa12dcf685eb0baa11176baee2391838f3fbf8"
"f81d8ab32151f4cd0205340a6736d22db72a8906df17f8ac48b9e39af090733f70f0d8232ab3ff8e10d72e6129"
"cab2507bb7db61e2e0f4f63bf58d315794ae840d1bf7d395e3509f36485fb6caeaf775b478391d8b89f1323b1a"
"921cb77ac656f22ec33354252dc017ad31e6df7204cbdb7c73a35857d5dd520d4c6db2d1ac33a8f54ccd362837"
"681484de652e54eda7516e72767e6e9ac8debb68497b07dbb45c1bdb97ed6b0dbbe503";

constexpr char divisor[] = "0x55c5374ad14e5c9bff62109df3100124f654bb11ef8fbdcc93e892fde002a462";

TEST(Modulo, CryptoPP) {
Aesi<8192> left (division), right (divisor), _ {};
for(std::size_t i = 0; i < 1024 * 16384; i += 16384)
_ = left % (right + i);
if(_.isZero()) std::cout << '1';
}

TEST(Modulo, GMP) {
mpz_class left (division), right (divisor), _ {};
for(std::size_t i = 0; i < 1024 * 16384; i += 16384)
_ = left % (right + i);
if(_ == 0) std::cout << '1';
}

TEST(Modulo, Aesi) {
CryptoPP::Integer left (division), right (divisor), _ {};
for(long long i = 0; i < 1024 * 16384; i += 16384)
_ = left % (right + i);
if(_.IsZero()) std::cout << '1';
}
43 changes: 40 additions & 3 deletions test/speed_comparison/multiplication.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
#include <gtest/gtest.h>
#include <thread>
#include <cryptopp/integer.h>
#include <gmpxx.h>
#include "../../Aesi.h"

constexpr char left[] = "0xa24872afd57464d79dfeec239367995f623429772ec032eb3bc9b376d0775c956dcb330a2c4f8f0d001f62fe6e0b"
"2e3b024d8f352522f3aa0ac7fbf05e7e3a2038e4650efb641862969f2437084448a28ff14d9c1e2def670babcf65a8"
"bcf32944a0f13525588a09a88a93e209ea0951e2ec64b7ec6904012f1c2f0528f9c68597e4cb39b33bae0dcc84a8c7"
"aa93733c0a5bb987b0c231e099aeb793c5fcbbdd9963aaff6ccbd2198b8898f71d60f8dcd8d0719f9b849951960c16"
"99b751dda0da6b9cc5a0ea9a04d126a00ce2c3bdaf8ea5e9123d34a00fbd21c31b12fa50d0a504f394bdce92bc1bc8"
"1af39a297c232e16af614ae8743a5333e2e1f016e08c09d7520f92da4a54de6819bec543645d4f3bc42c7948164c90"
"86cfd3b528ce5839125cfe4a991c66d69b6cf4cef13fb96095f774189943b189373bb931c5e7616f9b416de77d28c1"
"6a14a980f664352dc3b03026875f0db91a645a7acff73e79a815329df6c3dfac4c1ba96a1a9ce50b51cc1722f23586";

constexpr char right[] = "0xdb446efadae5960843e38dbdc26afc0c6d6633d0e3f7983b11d7610838b2707f3bcfeb19b071a967738efb939cf"
"e36278016a3127f0bbe2cc3ea8bb25d827ce4738db0275c95705462c52b13544a446fa14b4727aa6a472d766acb36"
"d6eb1cfc4508ba194b65e816a7343eff12d50669040a7629f04300a5bc4bb98df0191884b6d8236341854a1dcf0e3"
"d0f54615b1d9a4eb83fcd1ceecc0b906ad6cae9137baf43136d4e00a2638e7897e3b60b4330df9917e2f62742233c"
"24d325d42f14a9ba79f454a6cb5b3617e199335acaa4fd901721287498db25aac318abb51f2c4e9bc2e556168fd9c"
"7791285c4e30119bca7a4bd63db4f47fad992880389d21e03b1386a492326981cf8524b538cbfe4397df8bcfebc10"
"8bab8b2500ed99ac8b048a5307fc5ac4a03c5672fefde43454aa323be66e77e797b23d5865f7454be74195e7857ed"
"f825d5bb62a1a327148f4e8405f2ee2622122d3d8c967f2fdc6e05a8c1d40c93f3c0dfeb5b8b4c9f1755a9c26f351"
"ac1cdebf";

TEST(Multiplication, CryptoPP) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
for(std::size_t i = 0; i < 20; ++i) {
Aesi<4192> leftA (left), rightA (right), _ {};
for(std::size_t j = 0; j < 16384 * 16384; j += 16384)
_ = leftA * (rightA + j);
if(_.isZero()) std::cout << '1';
}
}

TEST(Multiplication, GMP) {
std::this_thread::sleep_for(std::chrono::milliseconds(130));
for(std::size_t i = 0; i < 15; ++i) {
mpz_class leftA (left), rightA (right), _ {};
for(std::size_t j = 0; j < 16384 * 16384; j += 16384)
_ = leftA * (rightA + j);
if(_ == 0) std::cout << '1';
}
}

TEST(Multiplication, Aesi) {
std::this_thread::sleep_for(std::chrono::milliseconds(170));
for(std::size_t i = 0; i < 15; ++i) {
CryptoPP::Integer leftA (left), rightA (right), _ {};
for(long long j = 0; j < 16384 * 16384; j += 16384)
_ = leftA * (rightA + j);
if(_.IsZero()) std::cout << '1';
}
}
60 changes: 60 additions & 0 deletions test/speed_comparison/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import sys
import numpy as np


def parse_xml_and_plot(xml_file, output, version):
tree = ET.parse(xml_file)
root = tree.getroot()

test_names = []
cryptopp_times = []
gmp_times = []
aesi_times = []

for testsuite in root.findall('testsuite'):
suite_name = testsuite.get('name')
test_names.append(suite_name)

for testcase in testsuite.findall('testcase'):
name = testcase.get('name')
time = float(testcase.get('time'))
if name == 'CryptoPP':
cryptopp_times.append(time)
elif name == 'GMP':
gmp_times.append(time)
elif name == 'Aesi':
aesi_times.append(time)

x = np.arange(len(test_names))
width = 0.25

fig, ax = plt.subplots()
rects3 = ax.bar(x + width, aesi_times, width, capstyle='butt', label='Aesi')
rects1 = ax.bar(x - width, cryptopp_times, width, capstyle='projecting', label='CryptoPP')
rects2 = ax.bar(x, gmp_times, width, capstyle='round', label='GMP')

ax.set_ylabel('Time (seconds)')
ax.set_title(f'Execution Time {version}\n(generated automatically)')
ax.set_xticks(x)
ax.set_xticklabels(test_names)
ax.legend()

fig.tight_layout()
plt.savefig(output, dpi=300)


if __name__ == '__main__':
measures = sys.argv[1]
output_image_path = sys.argv[2]
version = sys.argv[3]
print(f"Loading measures table from '{measures}'")
print(f"Output image location '{output_image_path}'")
print(f"Version '{version}'")

plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.size'] = 12

parse_xml_and_plot(measures, output_image_path, version)

Loading

0 comments on commit 9e6099b

Please sign in to comment.