diff --git a/homework/Savchenko/01/Timer.hpp b/homework/Savchenko/01/Timer.hpp new file mode 100644 index 0000000..ea2c1f5 --- /dev/null +++ b/homework/Savchenko/01/Timer.hpp @@ -0,0 +1,31 @@ + +#ifndef sum_by_rows_hpp +#define sum_by_rows_hpp + +#include +#include + +class Timer +{ + using clock_t = std::chrono::high_resolution_clock; + using microseconds = std::chrono::microseconds; +public: + Timer() + : start_(clock_t::now()) + { + } + + ~Timer() + { + const auto finish = clock_t::now(); + const auto us = + std::chrono::duration_cast + (finish - start_).count(); + std::cout << us << " us" << std::endl; + } + +private: + const clock_t::time_point start_; +}; + +#endif /* sum_by_rows_hpp */ diff --git a/homework/Savchenko/01/sum_by_col b/homework/Savchenko/01/sum_by_col new file mode 100755 index 0000000..1677a43 Binary files /dev/null and b/homework/Savchenko/01/sum_by_col differ diff --git a/homework/Savchenko/01/sum_by_col.cpp b/homework/Savchenko/01/sum_by_col.cpp new file mode 100644 index 0000000..cecc306 --- /dev/null +++ b/homework/Savchenko/01/sum_by_col.cpp @@ -0,0 +1,27 @@ +#include "Timer.hpp" +#include + +#define N 998 + +int sum_by_col() +{ + int arr[N][N]; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + arr[i][j] = (i + j) % 100; + + Timer timer; + + int sum = 0; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + sum += arr[j][i]; + + return sum; + +} + +int main() +{ + std::cout << sum_by_col() << std::endl; +} diff --git a/homework/Savchenko/01/sum_by_rows b/homework/Savchenko/01/sum_by_rows new file mode 100755 index 0000000..26893f8 Binary files /dev/null and b/homework/Savchenko/01/sum_by_rows differ diff --git a/homework/Savchenko/01/sum_by_rows.cpp b/homework/Savchenko/01/sum_by_rows.cpp new file mode 100644 index 0000000..3b2ddec --- /dev/null +++ b/homework/Savchenko/01/sum_by_rows.cpp @@ -0,0 +1,27 @@ +#include "Timer.hpp" +#include + +#define N 998 + +int sum_by_rows() +{ + int arr[N][N]; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + arr[i][j] = (i + j) % 100; + + Timer timer; + + int sum = 0; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + sum += arr[i][j]; + + return sum; + +} + +int main() +{ + std::cout << sum_by_rows() << std::endl; +}