calculating bytes per second
-
My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this. I am using a high-resolution performance counter, ive placed it in bold This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^] im not really sure if im getting the correct bytes per second
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "md5.h"#define MUL_BYTES 1024
#define MUL_KB (MUL_BYTES*1024)
#define MUL_MB (MUL_KB*1024)void Benchmark_MD5(void)
{
unsigned __int64 iPerf;
unsigned __int64 iBaseTime;
double dbFreq;unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
unsigned __int64 iValue;MD5_CTX md5;
int iPasses = 5000;QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
dbFreq = 1.0 / (double)iPerf;
QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);for (int i = 0; i < iPasses; i++) {
MD5Init(&md5, 0);
MD5Update(&md5, bzBuffer, 3);
MD5Final(&md5);
}//16 is for the length of the MD5 Digest added by the passes we tested
//then divided by the Seconds it took to runQueryPerformanceCounter((LARGE_INTEGER *)&iValue);
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
double bps = (double)((double)(16 + iPasses) / seconds);printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);
printf("RESULT:\t");
if (bps < MUL_BYTES)
printf(" %5.2f Bytes/sec\n", bps);
else if (bps < MUL_KB)
printf(" %5.2f KB/sec\n", bps / 1024);
else if (bps < MUL_MB)
printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
else
printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
}void main(void)
{
Benchmark_MD5();
} -
My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this. I am using a high-resolution performance counter, ive placed it in bold This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^] im not really sure if im getting the correct bytes per second
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "md5.h"#define MUL_BYTES 1024
#define MUL_KB (MUL_BYTES*1024)
#define MUL_MB (MUL_KB*1024)void Benchmark_MD5(void)
{
unsigned __int64 iPerf;
unsigned __int64 iBaseTime;
double dbFreq;unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
unsigned __int64 iValue;MD5_CTX md5;
int iPasses = 5000;QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
dbFreq = 1.0 / (double)iPerf;
QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);for (int i = 0; i < iPasses; i++) {
MD5Init(&md5, 0);
MD5Update(&md5, bzBuffer, 3);
MD5Final(&md5);
}//16 is for the length of the MD5 Digest added by the passes we tested
//then divided by the Seconds it took to runQueryPerformanceCounter((LARGE_INTEGER *)&iValue);
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
double bps = (double)((double)(16 + iPasses) / seconds);printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);
printf("RESULT:\t");
if (bps < MUL_BYTES)
printf(" %5.2f Bytes/sec\n", bps);
else if (bps < MUL_KB)
printf(" %5.2f KB/sec\n", bps / 1024);
else if (bps < MUL_MB)
printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
else
printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
}void main(void)
{
Benchmark_MD5();
}what are your results ?
-
what are your results ?
This is the results
DEBUG: [Passes = 5000] 311191.953 Byte/s
RESULT: 303.90 KB/secDEBUG: [Passes = 5000] 734956.927 Byte/s
RESULT: 717.73 KB/secDEBUG: [Passes = 5000] 391962.053 Byte/s
RESULT: 382.78 KB/secDEBUG: [Passes = 5000] 274082.350 Byte/s
RESULT: 267.66 KB/secDEBUG: [Passes = 5000] 281520.063 Byte/s
RESULT: 274.92 KB/sec -
My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this. I am using a high-resolution performance counter, ive placed it in bold This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^] im not really sure if im getting the correct bytes per second
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "md5.h"#define MUL_BYTES 1024
#define MUL_KB (MUL_BYTES*1024)
#define MUL_MB (MUL_KB*1024)void Benchmark_MD5(void)
{
unsigned __int64 iPerf;
unsigned __int64 iBaseTime;
double dbFreq;unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
unsigned __int64 iValue;MD5_CTX md5;
int iPasses = 5000;QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
dbFreq = 1.0 / (double)iPerf;
QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);for (int i = 0; i < iPasses; i++) {
MD5Init(&md5, 0);
MD5Update(&md5, bzBuffer, 3);
MD5Final(&md5);
}//16 is for the length of the MD5 Digest added by the passes we tested
//then divided by the Seconds it took to runQueryPerformanceCounter((LARGE_INTEGER *)&iValue);
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
double bps = (double)((double)(16 + iPasses) / seconds);printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);
printf("RESULT:\t");
if (bps < MUL_BYTES)
printf(" %5.2f Bytes/sec\n", bps);
else if (bps < MUL_KB)
printf(" %5.2f KB/sec\n", bps / 1024);
else if (bps < MUL_MB)
printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
else
printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
}void main(void)
{
Benchmark_MD5();
}saiyuk6=7 wrote:
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
To get seconds, shouldn't you be dividing by the timer's frequency?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
saiyuk6=7 wrote:
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
To get seconds, shouldn't you be dividing by the timer's frequency?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
I've updated the code somewhat now, i have taken your advice by dividing the timers freq i've changed how the bps is calculated as well double bps = (double)((ulSize * iPasses) / tm.Seconds()); i've multiplied the Size of the Buffer by the number of passes that runs in the for loop results are
DEBUG: 1074556249.047 Byte/s MEMSET: 0.00/sec 0.98/ms 1.00 GB/sec RESULT: 6.91/sec 6905.56/ms 72.41 MB/sec
class CTimer {
public:
CTimer() {
m_TimeStart.QuadPart = 0;
m_TimeStop.QuadPart = 0;
QueryPerformanceFrequency(&m_Frequency);
}void Start(void) {
QueryPerformanceCounter(&m_TimeStart);
}void Stop(void) {
QueryPerformanceCounter(&m_TimeStop);
}double Seconds() const {
return (double)(m_TimeStop.QuadPart - m_TimeStart.QuadPart) / (double)m_Frequency.QuadPart;;
}double Milliseconds() const {
return Seconds() * 1000.0;
}private:
double m_dbFreq;
LARGE_INTEGER m_Frequency;
LARGE_INTEGER m_TimeStart;
LARGE_INTEGER m_TimeStop;
};#define MUL_BYTES 1024.0
#define MUL_KB (MUL_BYTES*1024.0)
#define MUL_MB (MUL_KB*1024.0)
#define MUL_GB (MUL_MB*1024.0)std::string BPStoString(double dbPerSec)
{
char *pTemp[] = {
"Bytes", "KB", "MB",
"GB", "TB", "PB",
"EB", "ZB", "YB"
};
char szTemp[30];int i = 0;
while (dbPerSec >= 0.9 * MUL_BYTES) {
dbPerSec /= MUL_BYTES;
i++;
}sprintf(szTemp, "%5.2f %s/sec", dbPerSec, pTemp[i]);
return std::string(szTemp);
}void Benchmark_MD5(void)
{
CTimer tm;tm.Start();
unsigned long ulSize = MUL_KB;
unsigned char *bzBuffer = new unsigned char[ulSize];
if (bzBuffer != NULL) {
memset(bzBuffer, 0, ulSize);
tm.Stop();
double bps = (double)((ulSize * 1) / tm.Seconds());
printf("DEBUG: %5.3f Byte/s\n", bps);
printf("MEMSET: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
}tm.Start();
MD5_CTX md5;
int iPasses = 500;
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5);
MD5Update(&md5, bzBuffer, ulSize);
MD5Final(&md5);
}
tm.Stop();
double bps = (double)((ulSize * iPasses) / tm.Seconds());
printf("RESULT: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());delete bzBuffer;
} -
I've updated the code somewhat now, i have taken your advice by dividing the timers freq i've changed how the bps is calculated as well double bps = (double)((ulSize * iPasses) / tm.Seconds()); i've multiplied the Size of the Buffer by the number of passes that runs in the for loop results are
DEBUG: 1074556249.047 Byte/s MEMSET: 0.00/sec 0.98/ms 1.00 GB/sec RESULT: 6.91/sec 6905.56/ms 72.41 MB/sec
class CTimer {
public:
CTimer() {
m_TimeStart.QuadPart = 0;
m_TimeStop.QuadPart = 0;
QueryPerformanceFrequency(&m_Frequency);
}void Start(void) {
QueryPerformanceCounter(&m_TimeStart);
}void Stop(void) {
QueryPerformanceCounter(&m_TimeStop);
}double Seconds() const {
return (double)(m_TimeStop.QuadPart - m_TimeStart.QuadPart) / (double)m_Frequency.QuadPart;;
}double Milliseconds() const {
return Seconds() * 1000.0;
}private:
double m_dbFreq;
LARGE_INTEGER m_Frequency;
LARGE_INTEGER m_TimeStart;
LARGE_INTEGER m_TimeStop;
};#define MUL_BYTES 1024.0
#define MUL_KB (MUL_BYTES*1024.0)
#define MUL_MB (MUL_KB*1024.0)
#define MUL_GB (MUL_MB*1024.0)std::string BPStoString(double dbPerSec)
{
char *pTemp[] = {
"Bytes", "KB", "MB",
"GB", "TB", "PB",
"EB", "ZB", "YB"
};
char szTemp[30];int i = 0;
while (dbPerSec >= 0.9 * MUL_BYTES) {
dbPerSec /= MUL_BYTES;
i++;
}sprintf(szTemp, "%5.2f %s/sec", dbPerSec, pTemp[i]);
return std::string(szTemp);
}void Benchmark_MD5(void)
{
CTimer tm;tm.Start();
unsigned long ulSize = MUL_KB;
unsigned char *bzBuffer = new unsigned char[ulSize];
if (bzBuffer != NULL) {
memset(bzBuffer, 0, ulSize);
tm.Stop();
double bps = (double)((ulSize * 1) / tm.Seconds());
printf("DEBUG: %5.3f Byte/s\n", bps);
printf("MEMSET: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
}tm.Start();
MD5_CTX md5;
int iPasses = 500;
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5);
MD5Update(&md5, bzBuffer, ulSize);
MD5Final(&md5);
}
tm.Stop();
double bps = (double)((ulSize * iPasses) / tm.Seconds());
printf("RESULT: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());delete bzBuffer;
}saiyuk6=7 wrote:
unsigned char *bzBuffer = new unsigned char[ulSize];
Why not:
unsigned char bzBuffer[MUL_KB];
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
saiyuk6=7 wrote:
unsigned char *bzBuffer = new unsigned char[ulSize];
Why not:
unsigned char bzBuffer[MUL_KB];
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
well i've tried doing that but i get this error
bm.cpp
bm.cpp(40) : error C2057: expected constant expression
bm.cpp(40) : error C2466: cannot allocate an array of constant size 0
bm.cpp(40) : error C2133: 'bzBuffer' : unknown sizeWell i had started to allocate memory for it because later on i was going to start using a hash driver that i was going to make that would provide me with several hash algo's,.... example there might be errors below, but its just a example of what i had planned to do
unsigned char *bzBuffer;
for (int i = HT_MD5; i < (HT_WHIRLPOOL + 1); i++) {
hash.Init(i);
bzBuffer = new unsigned char[hash.DigestSize()];
if (bzBuffer == NULL) {
//err code here
return 0;
}
hash.Update(hashTest[i].buffer, hashTest[i].length);
hash.Final(bzBuffer);
for (int h = 0; h < hash.DigestSize(); h++)
printf("%02.2%", bzBuffer[i]);
delete bzBuffer;
}modified on Tuesday, July 20, 2010 12:28 PM