Created
January 28, 2009 16:12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <openssl/sha.h> | |
#include <openssl/md5.h> | |
#include <stdio.h> | |
#include <sys/time.h> | |
#include <stdint.h> | |
#include <memory.h> | |
#include <unistd.h> | |
static struct timeval g_timer; | |
void reset_timer() | |
{ | |
gettimeofday(&g_timer, NULL); | |
} | |
void show_timer(size_t size_bytes) | |
{ | |
struct timeval endtime; | |
double sec; | |
gettimeofday(&endtime, NULL); | |
sec = (endtime.tv_sec - g_timer.tv_sec) | |
+ (double)(endtime.tv_usec - g_timer.tv_usec) / 1000 / 1000; | |
printf("%f sec\n", sec); | |
printf("%f MB\n", ((double)size_bytes)/1024/1024); | |
printf("%f Mbps\n", ((double)size_bytes)*8/sec/1000/1000); | |
} | |
int main(void) | |
{ | |
const size_t NUM = 10000000; | |
const char data[] = "abcdefghijklmnopqrstuvwxyz"; | |
reset_timer(); | |
size_t i; | |
//unsigned char buf[MD5_DIGEST_LENGTH]; | |
unsigned char buf[SHA_DIGEST_LENGTH]; | |
for(i=0; i < NUM; ++i) { | |
//MD5((unsigned const char*)data, sizeof(data), buf); | |
SHA1((unsigned const char*)data, sizeof(data), buf); | |
} | |
show_timer(sizeof(data)*NUM); | |
return 0; | |
} | |
/** | |
* MD5: 3.872002 sec | |
* SHA1: 3.857552 sec | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment