mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 11:40:22 +00:00
LDGM: rewrite Timer_util with std::chrono
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "ldgm-session-cpu.h"
|
||||
//#include "timer-util.h"
|
||||
#include "timer-util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -256,8 +256,8 @@ LDGM_session_cpu::decode_frame ( char* received, int buf_size, int* frame_size,
|
||||
{
|
||||
// printf ( "buf_size: %d\n", buf_size );
|
||||
|
||||
//struct timeval t0,t1;
|
||||
//gettimeofday(&t0, 0);
|
||||
Timer_util interval;
|
||||
interval.start();
|
||||
|
||||
|
||||
Tanner_graph graph;
|
||||
@@ -434,11 +434,11 @@ LDGM_session_cpu::decode_frame ( char* received, int buf_size, int* frame_size,
|
||||
*frame_size = 0;
|
||||
|
||||
|
||||
//gettimeofday(&t1,0);
|
||||
//long elapsed = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;
|
||||
interval.end();
|
||||
long elapsed = interval.elapsed_time_us();
|
||||
//printf("time: %e\n",elapsed/1000.0 );
|
||||
//this->elapsed_sum2+=elapsed/1000.0;
|
||||
//this->no_frames2++;
|
||||
this->elapsed_sum2+=elapsed/1000.0;
|
||||
this->no_frames2++;
|
||||
|
||||
if(this->no_frames==150){
|
||||
//printf("TIME: %f ms\n",this->elapsed_sum/(double)this->no_frames );
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "ldgm-session-gpu.h"
|
||||
#include "ldgm-session-cpu.h"
|
||||
#include "gpu.cuh"
|
||||
//#include "timer-util.h"
|
||||
#include "timer-util.h"
|
||||
#include "tanner.h"
|
||||
|
||||
#include "crypto/crc.h"
|
||||
@@ -170,9 +170,8 @@ char *LDGM_session_gpu::decode_frame ( char *received_data, int buf_size, int *f
|
||||
{
|
||||
char *received = received_data;
|
||||
|
||||
//struct timeval t0, t1;
|
||||
//gettimeofday(&t0, 0);
|
||||
|
||||
Timer_util interval;
|
||||
interval.start();
|
||||
|
||||
int p_size = buf_size / (param_m + param_k);
|
||||
// printf("%d p_size K: %d, M: %d, buf_size: %d, max_row_weight: %d \n",p_size,param_k,param_m,buf_size,max_row_weight);
|
||||
@@ -367,11 +366,11 @@ char *LDGM_session_gpu::decode_frame ( char *received_data, int buf_size, int *f
|
||||
// printf("CRC NOK\n");
|
||||
// }
|
||||
|
||||
//gettimeofday(&t1, 0);
|
||||
//long elapsed = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec;
|
||||
interval.end();
|
||||
long elapsed = interval.elapsed_time_us();
|
||||
//printf("time: %e\n",elapsed/1000.0 );
|
||||
//this->elapsed_sum2 += elapsed / 1000.0;
|
||||
//this->no_frames2++;
|
||||
this->elapsed_sum2 += elapsed / 1000.0;
|
||||
this->no_frames2++;
|
||||
|
||||
return received + LDGM_session::HEADER_SIZE;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <string.h>
|
||||
#include "crypto/crc.h"
|
||||
#include "ldgm-session.h"
|
||||
//#include "timer-util.h"
|
||||
#include "timer-util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -119,8 +119,8 @@ char*
|
||||
LDGM_session::encode_frame ( char* frame, int frame_size, int* out_buf_size )
|
||||
{
|
||||
//printf("encode_frame\n");
|
||||
//struct timeval t0,t1;
|
||||
//gettimeofday(&t0, 0);
|
||||
Timer_util interval;
|
||||
interval.start();
|
||||
|
||||
int buf_size;
|
||||
int ps;
|
||||
@@ -161,11 +161,11 @@ LDGM_session::encode_frame ( char* frame, int frame_size, int* out_buf_size )
|
||||
this->encode ( (char*)out_buf, ((char*)out_buf)+param_k*ps );
|
||||
|
||||
|
||||
//gettimeofday(&t1,0);
|
||||
//long elapsed = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;
|
||||
interval.end();
|
||||
long elapsed = interval.elapsed_time_us();
|
||||
// printf("time: %e\n",elapsed/1000.0 );
|
||||
//this->elapsed_sum2+=elapsed/1000.0;
|
||||
//this->no_frames2++;
|
||||
this->elapsed_sum2+=elapsed/1000.0;
|
||||
this->no_frames2++;
|
||||
|
||||
return (char*)out_buf;
|
||||
|
||||
@@ -267,21 +267,18 @@ LDGM_session::encode_hdr_frame ( char *my_hdr, int my_hdr_size, char* frame, int
|
||||
assert(LDGM_session::HEADER_SIZE >= 12);
|
||||
#endif
|
||||
|
||||
//Timer_util t;
|
||||
|
||||
|
||||
//struct timeval t0, t1;
|
||||
//gettimeofday(&t0, 0);
|
||||
Timer_util interval;
|
||||
interval.start();
|
||||
|
||||
this->encode ( (char*)out_buf, ((char*)out_buf)+param_k*ps );
|
||||
|
||||
//gettimeofday(&t1,0);
|
||||
//long elapsed;
|
||||
interval.end();
|
||||
long elapsed;
|
||||
|
||||
//elapsed = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;
|
||||
elapsed = interval.elapsed_time_us();
|
||||
// printf("time: %e\n",elapsed/1000.0 );
|
||||
//this->elapsed_sum2+=elapsed/1000.0;
|
||||
//this->no_frames2++;
|
||||
this->elapsed_sum2+=elapsed/1000.0;
|
||||
this->no_frames2++;
|
||||
|
||||
|
||||
// gettimeofday(&t1,0);
|
||||
|
||||
@@ -10,72 +10,50 @@
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
#ifndef TIMER_INC
|
||||
#define TIMER_INC
|
||||
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
|
||||
#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ == 6 // compat, GCC 4.6 didn't have steady_clock
|
||||
#define steady_clock system_clock
|
||||
#endif
|
||||
|
||||
/*! \class Timer_util
|
||||
* \brief This class implements timer utils
|
||||
*/
|
||||
class Timer_util
|
||||
{
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::steady_clock> start_time;
|
||||
std::chrono::time_point<std::chrono::steady_clock> end_time;
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
Timer_util () {}
|
||||
/** Destructor */
|
||||
~Timer_util () {}
|
||||
inline void start() {
|
||||
start_time = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
inline void end() {
|
||||
end_time = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes time elapsed between start and end in second (as a real value)
|
||||
* Computes time elapsed between start and end in seconds (as a real value)
|
||||
*
|
||||
* @param start Point in time where timing started
|
||||
* @param end Point in time where timing stopped
|
||||
* @return Elapsed seconds as double value
|
||||
*/
|
||||
double
|
||||
elapsed_time ( timespec start, timespec end)
|
||||
inline double
|
||||
elapsed_time ()
|
||||
{
|
||||
timespec ts = dif(start, end);
|
||||
double temp = ts.tv_nsec/1000000;
|
||||
temp /= 1000;
|
||||
double clock = ts.tv_sec + temp;
|
||||
return clock;
|
||||
return std::chrono::duration_cast<std::chrono::duration<double>>(end_time - start_time).count();
|
||||
}
|
||||
|
||||
double
|
||||
elapsed_time_us ( timespec start, timespec end)
|
||||
inline long
|
||||
elapsed_time_us ()
|
||||
{
|
||||
timespec ts = dif(start, end);
|
||||
double temp = ts.tv_nsec/1000;
|
||||
// temp /= 1000;
|
||||
double clock = ts.tv_sec + temp;
|
||||
return clock;
|
||||
return std::chrono::duration_cast<std::chrono::duration<long, std::micro>>(end_time - start_time).count();
|
||||
}
|
||||
/**
|
||||
* @param start Point in time where timing started
|
||||
* @param end Point in time where timing stopped
|
||||
* @return Elapsed time as timespec structure
|
||||
*/
|
||||
timespec
|
||||
dif(timespec start, timespec end) {
|
||||
timespec temp;
|
||||
if ((end.tv_nsec-start.tv_nsec)<0) {
|
||||
temp.tv_sec = end.tv_sec-start.tv_sec-1;
|
||||
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
|
||||
} else {
|
||||
temp.tv_sec = end.tv_sec-start.tv_sec;
|
||||
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
}; /* ----- end of class Timer_util ----- */
|
||||
|
||||
#endif /* ----- #ifndef TIMER_INC ----- */
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user