Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

calibrate_crunch.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: calibrate_crunch.cc,v 1.3 2004/05/19 15:56:46 mmarsh Exp $
00008 //
00009 // $Log: calibrate_crunch.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:46  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:07:35  mmarsh
00014 // General code cleanup and reorganization.
00015 //
00016 //
00017 
00018 #include <unistd.h>
00019 #include <signal.h>
00020 #include <iostream>
00021 #include <iomanip>
00022 #include <sys/resource.h>
00023 #include <sys/time.h>
00024 #include <openssl/ssl.h>
00025 #include <openssl/rand.h>
00026 
00027 using namespace std;
00028 
00029 int main( int argc, char** argv )
00030 {
00031    //============================================================
00032    // Seed the random number generator.
00033    //============================================================
00034    unsigned char seed[40] = 
00035    {0x38,0x4F,0x67,0x4C,0xA6,0x02,0x3D,0x9E,
00036     0x69, 0x2c, 0x3f, 0xfd, 0x98, 0x50, 0xcc,
00037     0x76, 0xfa, 0x78, 0x34, 0x12, 0x23, 0xdf,
00038     0x8a, 0xd4, 0x34, 0xcd, 0x98, 0x59, 0x19,
00039     0x35, 0x4f, 0xda, 0xed, 0x4e, 0x99, 0x0f};
00040    RAND_seed(seed,40);
00041 
00042 
00043    //============================================================
00044    // Load SSLeay algorithms
00045    //============================================================
00046    SSL_load_error_strings();
00047    SSLeay_add_ssl_algorithms();
00048 
00049    for ( int i = 0 ; i < 100 ; ++i )
00050    {
00051       // initial time
00052       struct rusage ru1;
00053       struct timeval tv1;
00054       getrusage(RUSAGE_SELF,&ru1);
00055       gettimeofday(&tv1,0);
00056 
00057       // CPU-intensive task
00058       const unsigned int kNumBits = 512;
00059       BIGNUM * p = BN_new();
00060       if ( 0 == p )
00061       {
00062          throw __LINE__;
00063       }
00064       if ( 0 == BN_generate_prime( p, kNumBits, 1, 0, 0, 0, 0 ) )
00065       {
00066          throw __LINE__;
00067       }
00068       BN_clear_free(p);
00069 
00070       // ending time
00071       struct rusage ru2;
00072       struct timeval tv2;
00073       getrusage(RUSAGE_SELF,&ru2);
00074       gettimeofday(&tv2,0);
00075 
00076       // print statistics
00077       long int rt =
00078          ( ru2.ru_utime.tv_sec  - ru1.ru_utime.tv_sec  ) * 1000000 +
00079          ( ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec );
00080       long int t =
00081          ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + ( tv2.tv_usec - tv1.tv_usec );
00082       cout << rt << " " << t << endl;
00083    }
00084 }

Generated on Wed Jun 2 16:32:54 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18