FreeBSD/sbin/md5/md5.c
/*
 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
 */
Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN - byte blocks .
static void
MDTimeTrial(const Algorithm_t *alg)
{
	DIGEST_CTX context;
	struct rusage before, after;
	struct timeval total;
	float seconds;
	unsigned char block[TEST_BLOCK_LEN];
	unsigned int i;
	char *p, buf[HEX_DIGEST_LENGTH];
	printf("%s time trial. Digesting %d %d-byte blocks ...",
	    alg->name, TEST_BLOCK_COUNT, TEST_BLOCK_LEN);
	fflush(stdout);
	for (i = 0; i < TEST_BLOCK_LEN; i++)
		block[i] = (unsigned char) (i & 0xff);
	getrusage(RUSAGE_SELF, &before);
	alg->Init(&context);
	for (i = 0; i < TEST_BLOCK_COUNT; i++)
		alg->Update(&context, block, TEST_BLOCK_LEN);
	p = alg->End(&context, buf);
	getrusage(RUSAGE_SELF, &after);
	timersub(&after.ru_utime, &before.ru_utime, &total);
	seconds = total.tv_sec + (float) total.tv_usec / 1000000;
	printf(" done\n");
	printf("Digest = %s", p);
	printf("\nTime = %f seconds\n", seconds);
	printf("Speed = %f MiB/second\n", (float) TEST_BLOCK_LEN * 
		(float) TEST_BLOCK_COUNT / seconds / (1 << 20));
}
static void MDTimeTrial ( const Algorithm_t * alg ) { DIGEST_CTX context ; struct rusage before , after ; struct timeval total ; float seconds ; unsigned char block [ TEST_BLOCK_LEN ] ; unsigned int i ; char * p , buf [ HEX_DIGEST_LENGTH ] ; printf ( " " , alg -> name , TEST_BLOCK_COUNT , TEST_BLOCK_LEN ) ; fflush ( stdout ) ; for ( i = 0 ; i < TEST_BLOCK_LEN ; i ++ ) block [ i ] = ( unsigned char ) ( i & 0xff ) ; getrusage ( RUSAGE_SELF , & before ) ; alg -> Init ( & context ) ; for ( i = 0 ; i < TEST_BLOCK_COUNT ; i ++ ) alg -> Update ( & context , block , TEST_BLOCK_LEN ) ; p = alg -> End ( & context , buf ) ; getrusage ( RUSAGE_SELF , & after ) ; timersub ( & after . ru_utime , & before . ru_utime , & total ) ; seconds = total . tv_sec + ( float ) total . tv_usec / 1000000 ; printf ( " \n " ) ; printf ( " " , p ) ; printf ( " \n \n " , seconds ) ; printf ( " \n " , ( float ) TEST_BLOCK_LEN * ( float ) TEST_BLOCK_COUNT / seconds / ( 1 << 20 ) ) ; }
Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN - byte blocks .
/* Initialize block */ /* Start timer */ /* Digest blocks */ /* Stop timer */