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
25 changes: 25 additions & 0 deletions homework/Korekov/01/Timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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_;
};
48 changes: 48 additions & 0 deletions homework/Korekov/01/sum_by_columns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Timer.h"

#include <iostream>

#define SIZE 506


int my_function()

{

volatile int arr[SIZE][SIZE];

volatile int sum = 0;
for (int i = 0; i < SIZE; i++)

for (int j = 0; j < SIZE; j++)

arr[i][j] = 1;

Timer t;

for (int i = 0; i < SIZE; i++)

for (int j = 0; j < SIZE; j++)

sum += arr[i][j];

return sum;

}


int main()

{

std::cout << my_function() << std:: endl;

int n;

std::cin >> n;

return 0;

}


Binary file added homework/Korekov/01/sum_by_columns.exe
Binary file not shown.
48 changes: 48 additions & 0 deletions homework/Korekov/01/sum_by_rows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Timer.h"

#include <iostream>

#define SIZE 506


int my_function()

{

volatile int arr[SIZE][SIZE];
volatile int sum = 0;

for (int i = 0; i < SIZE; i++)

for (int j = 0; j < SIZE; j++)

arr[i][j] = 1;

Timer t;

for (int i = 0; i < SIZE; i++)

for (int j = 0; j < SIZE; j++)

sum += arr[j][i];

return sum;

}


int main()

{

std::cout << my_function() << std:: endl;

int n;

std::cin >> n;

return 0;

}


Binary file added homework/Korekov/01/sum_by_rows.exe
Binary file not shown.