Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Gervasio Daniel Perez
aed2-2c2017-tp3
Commits
7dc4e5c1
Commit
7dc4e5c1
authored
7 years ago
by
Gervasio Perez
Browse files
Options
Download
Email Patches
Plain Diff
V 1.3 - Timing preciso
parent
7aea55cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
40 deletions
+59
-40
CHANGELOG.md
CHANGELOG.md
+4
-0
CMakeLists.txt
CMakeLists.txt
+1
-1
tests/test-matrix-mult.cpp
tests/test-matrix-mult.cpp
+11
-10
tests/test-ordenar-billetes.cpp
tests/test-ordenar-billetes.cpp
+25
-29
tests/timing.h
tests/timing.h
+18
-0
No files found.
CHANGELOG.md
View file @
7dc4e5c1
## [1.3] - 2017-12-02
-
Mediciones de tiempos más precisas
## [1.2] - 2017-11-17
-
Actualización de normas de entrega
...
...
This diff is collapsed.
Click to expand it.
CMakeLists.txt
View file @
7dc4e5c1
...
...
@@ -4,7 +4,7 @@ project(tp3)
set
(
CMAKE_CXX_STANDARD 11
)
# Algunos flags para pasar al compilador (gnu++11 en vez de c++11 para que sea cross-plat)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=gnu++11 -ggdb3 -g -O2"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=gnu++11 -ggdb3 -g -O2
-DTEST_TIMING
"
)
# Leemos todos los archivos fuentes en ./src
file
(
GLOB SOURCE_FILES src/*
)
...
...
This diff is collapsed.
Click to expand it.
tests/test-matrix-mult.cpp
View file @
7dc4e5c1
#include <gtest/gtest.h>
#include "../src/tp3.h"
#include <chrono>
#include "timing.h"
#include <iostream>
TEST
(
test_multiplicacion
,
test_matriz_cuadrada
)
{
...
...
@@ -30,19 +29,21 @@ TEST(test_multiplicacion, test_matriz_cuadrada) {
));
}
#ifdef TEST_TIMING
TEST
(
test_multiplicacion
,
test_matriz_gigante
)
{
size_t
T0
,
T1
;
// una matriz un poco más grande
Matriz
M4
=
crear
(
1024
,
1.0
);
auto
t0
=
std
::
chrono
::
system_clock
::
now
();
Matriz
M5
=
multiplicar_strassen
(
M4
,
M4
,
32
);
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
Matriz
M4
=
crear
(
1024
,
1.0
),
M5
,
M6
;
TIME
(
M5
=
multiplicar_strassen
(
M4
,
M4
,
32
),
RUN_TIMES
,
T0
);
EXPECT_FLOAT_EQ
(
M5
[
0
][
0
],
M5
.
size
());
auto
t2
=
std
::
chrono
::
system_clock
::
now
();
Matriz
M6
=
multiplicar_strassen
(
M4
,
M4
,
M4
.
size
());
auto
t3
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
M6
=
multiplicar
(
M4
,
M4
),
RUN_TIMES
,
T1
);
EXPECT_FLOAT_EQ
(
M5
[
0
][
0
],
M5
.
size
());
auto
d
=
double
((
t1
-
t0
).
count
())
/
(
t3
-
t2
).
count
();
auto
d
=
double
(
T0
)
/
T1
;
std
::
cout
<<
"T0: "
<<
T0
<<
std
::
endl
;
std
::
cout
<<
"T1: "
<<
T1
<<
std
::
endl
;
std
::
cout
<<
"D: "
<<
d
<<
std
::
endl
;
EXPECT_LT
(
d
,
0.4
);
}
#endif
This diff is collapsed.
Click to expand it.
tests/test-ordenar-billetes.cpp
View file @
7dc4e5c1
#include <gtest/gtest.h>
#include "../src/tp3.h"
#include
<chrono>
#include
"timing.h"
#include <random>
fajo
ordenar_billetes_naif
(
const
fajo
&
falsos
,
const
fajo
&
a_ordenar
)
{
...
...
@@ -64,8 +64,12 @@ TEST(ordenar_billetes, test_basico) {
}
#ifdef TEST_TIMING
TEST
(
ordenar_billetes
,
test_billetera_grande
)
{
fajo
todos
,
falsos
;
fajo
res
,
res2
;
size_t
T0
,
T1
;
todos
.
reserve
(
26
*
100000
);
int
count_falsos
=
0
;
...
...
@@ -89,24 +93,19 @@ TEST(ordenar_billetes, test_billetera_grande) {
}
}
}
auto
t0
=
std
::
chrono
::
system_clock
::
now
();
fajo
res
=
ordenar_por_probabilidad
(
falsos
,
todos
);
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res
=
ordenar_por_probabilidad
(
falsos
,
todos
),
RUN_TIMES
,
T0
);
EXPECT_EQ
(
res
.
front
(),
billete
(
199991996
));
EXPECT_EQ
(
res
[
count_falsos
-
1
].
probabilidad_falso
,
probabilidad_max
);
EXPECT_LE
(
res
[
count_falsos
].
probabilidad_falso
,
probabilidad_max
);
EXPECT_EQ
(
res
[
res
.
size
()
/
2
],
billete
(
168912003
));
EXPECT_EQ
(
res
.
back
(),
billete
(
100002016
));
std
::
cout
<<
"T0: "
<<
T0
<<
std
::
endl
;
std
::
cout
<<
"T0: "
<<
(
t1
-
t0
).
count
()
<<
std
::
endl
;
auto
t2
=
std
::
chrono
::
system_clock
::
now
();
auto
res2
=
ordenar_billetes_naif
(
falsos
,
todos
);
auto
t3
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res2
=
ordenar_billetes_naif
(
falsos
,
todos
),
RUN_TIMES
,
T1
);
std
::
cout
<<
"T1: "
<<
T1
<<
std
::
endl
;
std
::
cout
<<
"T1: "
<<
(
t3
-
t2
).
count
()
<<
std
::
endl
;
auto
d
=
double
((
t1
-
t0
).
count
())
/
(
t3
-
t2
).
count
();
auto
d
=
double
(
T0
)
/
T1
;
std
::
cout
<<
"T0/T1: "
<<
d
<<
std
::
endl
;
EXPECT_EQ
(
res
,
res2
);
...
...
@@ -115,6 +114,8 @@ TEST(ordenar_billetes, test_billetera_grande) {
TEST
(
ordenar_billetes
,
test_pocos_anios_muchos_falsos
)
{
fajo
todos
,
falsos
;
fajo
res
,
res2
;
size_t
T0
,
T1
;
todos
.
reserve
(
10000
);
int
count_falsos
=
0
;
...
...
@@ -139,9 +140,7 @@ TEST(ordenar_billetes, test_pocos_anios_muchos_falsos) {
falsos
.
push_back
(
billete
(
falsos
[
i
].
numero_de_serie
+
200000000000
));
falsos
.
push_back
(
billete
(
falsos
[
i
].
numero_de_serie
+
300000000000
));
}
auto
t0
=
std
::
chrono
::
system_clock
::
now
();
fajo
res
=
ordenar_por_probabilidad
(
falsos
,
todos
);
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res
=
ordenar_por_probabilidad
(
falsos
,
todos
),
RUN_TIMES
,
T0
);
EXPECT_EQ
(
res
.
front
(),
billete
(
199981991
));
EXPECT_EQ
(
res
[
count_falsos
-
1
].
probabilidad_falso
,
probabilidad_max
);
...
...
@@ -149,14 +148,12 @@ TEST(ordenar_billetes, test_pocos_anios_muchos_falsos) {
EXPECT_EQ
(
res
[
res
.
size
()
/
2
],
billete
(
199991991
));
EXPECT_EQ
(
res
.
back
(),
billete
(
100011991
));
std
::
cout
<<
"T0: "
<<
(
t1
-
t0
).
count
()
<<
std
::
endl
;
std
::
cout
<<
"T0: "
<<
T0
<<
std
::
endl
;
auto
t2
=
std
::
chrono
::
system_clock
::
now
();
auto
res2
=
ordenar_billetes_naif
(
falsos
,
todos
);
auto
t3
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res2
=
ordenar_billetes_naif
(
falsos
,
todos
),
RUN_TIMES
,
T1
);
std
::
cout
<<
"T1: "
<<
T1
<<
std
::
endl
;
std
::
cout
<<
"T1: "
<<
(
t3
-
t2
).
count
()
<<
std
::
endl
;
auto
d
=
double
((
t1
-
t0
).
count
())
/
(
t3
-
t2
).
count
();
auto
d
=
double
(
T0
)
/
T1
;
std
::
cout
<<
"T0/T1: "
<<
d
<<
std
::
endl
;
EXPECT_EQ
(
res
,
res2
);
...
...
@@ -165,6 +162,8 @@ TEST(ordenar_billetes, test_pocos_anios_muchos_falsos) {
TEST
(
ordenar_billetes
,
test_muchos_anios_pocos_falsos
)
{
fajo
todos
,
falsos
;
fajo
res
,
res2
;
size_t
T0
,
T1
;
todos
.
reserve
(
2015000
);
int
count_falsos
=
0
;
...
...
@@ -183,9 +182,7 @@ TEST(ordenar_billetes, test_muchos_anios_pocos_falsos) {
}
}
}
auto
t0
=
std
::
chrono
::
system_clock
::
now
();
fajo
res
=
ordenar_por_probabilidad
(
falsos
,
todos
);
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res
=
ordenar_por_probabilidad
(
falsos
,
todos
),
RUN_TIMES
,
T0
);
EXPECT_EQ
(
res
.
front
(),
billete
(
11012016
));
EXPECT_EQ
(
res
[
count_falsos
-
1
].
probabilidad_falso
,
probabilidad_max
);
...
...
@@ -193,16 +190,15 @@ TEST(ordenar_billetes, test_muchos_anios_pocos_falsos) {
EXPECT_EQ
(
res
[
res
.
size
()
/
2
],
billete
(
15002016
));
EXPECT_EQ
(
res
.
back
(),
billete
(
10000001
));
std
::
cout
<<
"T0: "
<<
(
t1
-
t0
).
count
()
<<
std
::
endl
;
std
::
cout
<<
"T0: "
<<
T0
<<
std
::
endl
;
auto
t2
=
std
::
chrono
::
system_clock
::
now
();
auto
res2
=
ordenar_billetes_naif
(
falsos
,
todos
);
auto
t3
=
std
::
chrono
::
system_clock
::
now
();
TIME
(
res2
=
ordenar_billetes_naif
(
falsos
,
todos
),
RUN_TIMES
,
T1
);
std
::
cout
<<
"T1: "
<<
T1
<<
std
::
endl
;
std
::
cout
<<
"T1: "
<<
(
t3
-
t2
).
count
()
<<
std
::
endl
;
auto
d
=
double
((
t1
-
t0
).
count
())
/
(
t3
-
t2
).
count
();
auto
d
=
double
(
T0
)
/
T1
;
std
::
cout
<<
"T0/T1: "
<<
d
<<
std
::
endl
;
EXPECT_EQ
(
res
,
res2
);
EXPECT_LE
(
d
,
0.25
);
}
#endif // TEST_TIMING
This diff is collapsed.
Click to expand it.
tests/timing.h
0 → 100644
View file @
7dc4e5c1
#ifndef TIMING_H_INCLUDED
#define TIMING_H_INCLUDED
#include <chrono>
const
unsigned
RUN_TIMES
=
10
;
#define TIME(EXPR_TO_EVAL,N,var_t)\
{ size_t count = 0;\
for (int j=0; j < N; ++j) {\
auto t0 = std::chrono::system_clock::now();\
EXPR_TO_EVAL;\
auto t1 = std::chrono::system_clock::now();\
count += (t1-t0).count();}\
var_t = count / N; }
#endif // TIMING_H_INCLUDED
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment