I wrote a small application to measure performace of adler32 from various libraries, the result however suprised me. Every implementation was returning different values!
versions: cryptopp552 (just untarred and issued make) GCC Red Hat 4.0.2-14 Linux beta 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:32:02 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux [EMAIL PROTECTED] hash]$ g++ -c -O3 ad32.cpp -I/home/wijata/tmp/src/cr++ [EMAIL PROTECTED] hash]$ g++ ad32.o /home/wijata/tmp/src/cr++/libcryptopp.a -lz [EMAIL PROTECTED] hash]$ ./a.out Initializing vector of chunks 204800*6144b=1258291200 Initializing vector done computing wiki/adler32 done in 5:149 s=2970464768 computing zlib/adler32 done in 4:041 s=122658048 computing crypto++/adler32 done in 4:558 s=2612860096 can anybody explain the different results? Maybe my code is wrong. But then, the very alike program was testing crc32 (zlib, crypto++, boost), and all three matched in that case. the test programm follows: #include <iostream> #include <sstream> #include <string> #include <vector> #include <iomanip> #include <sys/time.h> #include "/usr/include/zlib.h" //zlib #include "adler32.h" //crypto++ using namespace std; #define CHUNKS 204800 #define CHUNKSIZE 6144 typedef unsigned int uint32; // http://en.wikipedia.org/wiki/Adler32#Example_implementation #define MOD_ADLER 65521 uint32 wadler(char *data, uint32 len) { uint32 a = 1, b = 0; while (len > 0) { uint32 tlen = len > 5550 ? 5550 : len; len -= tlen; do { a += *data++; b += a; } while (--tlen); a %= MOD_ADLER; b %= MOD_ADLER; } return (b << 16) | a; } std::string print_duration(struct timeval &tv1, struct timeval &tv2) { unsigned int tvs, tvms; tvs = tv2.tv_sec - tv1.tv_sec; if (tv2.tv_usec < tv1.tv_usec) //one second less { tvs--; tvms = (tv2.tv_usec + 1000000 - tv1.tv_usec) / 1000; } else { tvms = (tv2.tv_usec - tv1.tv_usec) / 1000; } ostringstream s; s << tvs << ":" << setw(3) << setfill('0') << tvms; return s.str(); } int main() { struct timeval tv1,tv2; uint32 volatile dummy = 0; cout << "Initializing vector of chunks " << CHUNKS << "*" << CHUNKSIZE << "b=" << CHUNKS*CHUNKSIZE << endl; vector<char *> chunks(CHUNKS, (char*)(0)); char filler = 'a'; for(int i = 0; i < CHUNKS; ++i) { chunks[i] = (char*)malloc(CHUNKSIZE); memset(chunks[i], filler++, CHUNKSIZE/2); memset(chunks[i]+CHUNKSIZE/2, filler++, CHUNKSIZE/2); } for(int i = 0; i < CHUNKS; ++i) { uint32 za = adler32(0L, 0, 0); za = adler32(za, (Bytef*)chunks[i], CHUNKSIZE); dummy += za; } cout << "Initializing vector done" << endl; dummy = 0; gettimeofday(&tv1, NULL); for(int c = 0; c < 5; ++c) for(int i = 0; i < CHUNKS; ++i) { uint32 za = wadler(chunks[i], CHUNKSIZE); dummy += za; } gettimeofday(&tv2, NULL); cout << "computing wiki/adler32 done in " << print_duration(tv1, tv2) << " s=" << dummy << endl; dummy = 0; gettimeofday(&tv1, NULL); for(int c = 0; c < 5; ++c) for(int i = 0; i < CHUNKS; ++i) { uint32 za = adler32(0L, Z_NULL, 0); za = adler32(za, (Bytef*)chunks[i], CHUNKSIZE); dummy += za; } gettimeofday(&tv2, NULL); cout << "computing zlib/adler32 done in " << print_duration(tv1, tv2) << " s=" << dummy << endl; dummy = 0; gettimeofday(&tv1, NULL); for(int c = 0; c < 5; ++c) for(int i = 0; i < CHUNKS; ++i) { uint32 sum; CryptoPP::Adler32 h32; h32.Update((byte*)chunks[i], CHUNKSIZE); h32.TruncatedFinal((byte*)&sum, 4); dummy += sum; } gettimeofday(&tv2, NULL); cout << "computing crypto++/adler32 done in " << print_duration(tv1, tv2) << " s=" << dummy << endl; for(int i = 0; i < CHUNKS; ++i) { free(chunks[i]); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [EMAIL PROTECTED] More information about Crypto++ and this group is available at http://www.cryptopp.com. -~----------~----~----~----~------~----~------~--~---
