Commit 7dc4e5c1 authored by Gervasio Perez's avatar Gervasio Perez
Browse files

V 1.3 - Timing preciso

parent 7aea55cf
## [1.3] - 2017-12-02
- Mediciones de tiempos más precisas
## [1.2] - 2017-11-17
- Actualización de normas de entrega
......
......@@ -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/*)
......
#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
#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
#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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment