Fixed timer implementation and call

This commit is contained in:
balhau@balhau.net 2021-12-25 19:27:44 +00:00
parent 7345dd2665
commit 03748b446b
No known key found for this signature in database
GPG key ID: 1E666F326A121830
3 changed files with 16 additions and 23 deletions

View file

@ -1,4 +1,5 @@
#include <iostream>
#include <unistd.h>
#include "../src/cpu/utils.hpp"
#include "../src/cpu/x86/sse.hpp"
#include "../src/cpu/naive.hpp"
@ -12,7 +13,7 @@ using namespace std;
void naive128(UInt *v1_128, UInt *v2_128)
{
Timer("Naive 128: ");
Timer t=Timer("Naive 128: ");
for (int i = 0; i < MAX_ITER; i++)
{
Naive::add_128(v1_128, v2_128);
@ -21,7 +22,7 @@ void naive128(UInt *v1_128, UInt *v2_128)
void int128(SSE *sse, UInt *v1_128, UInt *v2_128)
{
Timer("SIMD(Int) 128: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_128(v1_128, v2_128);
@ -30,7 +31,7 @@ void int128(SSE *sse, UInt *v1_128, UInt *v2_128)
void long128(SSE *sse, ULong *v1_128_l, ULong *v2_128_l)
{
Timer("SIMD(Long) 128: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_128(v1_128_l, v2_128_l);
@ -39,7 +40,7 @@ void long128(SSE *sse, ULong *v1_128_l, ULong *v2_128_l)
void byte128(SSE *sse, UChar *c1_128, UChar *c2_128)
{
Timer("SIMD(Byte) 128: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_128(c1_128, c2_128);
@ -48,7 +49,7 @@ void byte128(SSE *sse, UChar *c1_128, UChar *c2_128)
void naive256(UInt *v1_256, UInt *v2_256)
{
Timer("Naive 256: ");
Timer t=Timer("Naive 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
Naive::add_256(v1_256, v2_256);
@ -57,7 +58,7 @@ void naive256(UInt *v1_256, UInt *v2_256)
void int256(SSE *sse, UInt *v1_256, UInt *v2_256)
{
Timer("SIMD(Int) 256: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_256(v1_256, v2_256);
@ -66,7 +67,7 @@ void int256(SSE *sse, UInt *v1_256, UInt *v2_256)
void long256(SSE *sse, ULong *v1_256, ULong *v2_256)
{
Timer("SIMD(Long) 256: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_256(v1_256, v2_256);
@ -75,7 +76,7 @@ void long256(SSE *sse, ULong *v1_256, ULong *v2_256)
void byte256(SSE *sse, UChar *v1_256, UChar *v2_256)
{
Timer("SIMD(Byte) 256: ");
Timer t=Timer("SIMD(Byte) 256: ");
for (int i = 0; i < MAX_ITER; i++)
{
sse->add_256(v1_256, v2_256);

View file

@ -62,6 +62,7 @@
};
//X86 Assembly to add two 256 bit numbers in the form of packed long 64bit
//Here we are using vmovdqu instead of vmovdqa because memory is not aligned.
void cpu::SSE::add_256(ULong *a,ULong *b) {
asm volatile(
"vmovdqu %0, %%ymm1\n"

View file

@ -1,8 +1,7 @@
#pragma once
#include <iostream>
#include <sys/time.h>
#include <unistd.h>
#include <chrono>
namespace platform
{
@ -10,28 +9,20 @@ namespace platform
{
private:
std::string label;
long int start;
long int end;
long int gettime()
{
struct timeval tp;
gettimeofday(&tp, NULL);
return (double)(tp.tv_sec * 1000 + (double)tp.tv_usec / 1000);
};
std::chrono::high_resolution_clock::time_point start;
std::chrono::high_resolution_clock::time_point end;
public:
Timer(const char *lbl)
{
this->label = std::string(lbl);
this->start = this->gettime();
this->start = std::chrono::high_resolution_clock::now();
}
~Timer()
{
this->end = this->gettime();
unsigned long diff = this->end - this->start;
std::cout << this->label << diff << std::endl;
this->end = std::chrono::high_resolution_clock::now();
std::cout << this->label << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() << std::endl;
}
};
};