forked from Roman-Oliynykov/ciphers-speed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_measure.cpp
50 lines (34 loc) · 1.14 KB
/
time_measure.cpp
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
44
45
46
47
48
49
50
/*
Implementation of funcions for
- measuring running time for encryption;
- encryption speed calculation based on memory amount and elapsed processor time;
- memory initialization before encryption (preventing extra compiler optimization)
Author: Roman Oliynykov
*/
#include <sys/time.h>
#include <iostream>
using std::cerr;
using std::endl;
#include "time_measure.hpp"
ENCRYPTED_MEMORY encrypted_memory;
unsigned long long resolution_ticks;
void DetermineTime(struct timeval& ticks)
{
gettimeofday(&ticks, NULL);
}
double CalculateEncryptionSpeedMemory(struct timeval& t1, struct timeval& t2 )
{
double elapsedTime = 0.0; /* ms */
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
return number_of_reencryptions_in_memory * double( memory_amount_for_encryption ) * 1024 * 1024 * 8 / \
elapsedTime / 1000;
}
void InitMemoryEncryptionBlock()
{
for(unsigned int i = 0; i < number_of_blocks_in_memory_128; i++)
{
encrypted_memory.block128[ i ][ 0 ] = i;
encrypted_memory.block128[ i ][ 1 ] = i << 4;
}
}