-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2darrays.cpp
More file actions
43 lines (41 loc) · 941 Bytes
/
Copy path2darrays.cpp
File metadata and controls
43 lines (41 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "timer.h"
#include <iostream>
int main() {
{
Timer timer;
// using a 2d array
int **a2d = new int *[50000];
for (int i = 0; i < 50000; i++) {
a2d[i] = new int[5];
}
// assigning value to the array
for (int i = 0; i < 50000; i++) {
for (int j = 0; j < 5; j++) {
a2d[i][j] = 2;
}
}
// accesing the value from the array and prinint it
for (int i = 0; i < 50000; i++) {
for (int j = 0; j < 5; j++) {
int a = a2d[i][j];
}
// std::cout << std::endl;
}
}
{
Timer timer;
int *a2d_fast = new int[50000 * 5];
// assigning value to the array
for (int i = 0; i < 50000; i++) {
for (int j = 0; j < 5; j++) {
a2d_fast[i * 5 + j] = 2;
}
}
for (int i = 0; i < 50000; i++) {
for (int j = 0; j < 5; j++) {
int a = a2d_fast[i * 5 + j];
}
// std::cout << std::endl;
}
}
}