Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions homework/Savchenko/01/Timer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#ifndef sum_by_rows_hpp
#define sum_by_rows_hpp

#include <chrono>
#include <iostream>

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<microseconds>
(finish - start_).count();
std::cout << us << " us" << std::endl;
}

private:
const clock_t::time_point start_;
};

#endif /* sum_by_rows_hpp */
Binary file added homework/Savchenko/01/sum_by_col
Binary file not shown.
27 changes: 27 additions & 0 deletions homework/Savchenko/01/sum_by_col.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "Timer.hpp"
#include <iostream>

#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;
}
Binary file added homework/Savchenko/01/sum_by_rows
Binary file not shown.
27 changes: 27 additions & 0 deletions homework/Savchenko/01/sum_by_rows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "Timer.hpp"
#include <iostream>

#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;
}