From 18f8ebb9dcd52edf784d9e8f1666b819866e5b96 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 17 Oct 2014 17:10:43 -0400 Subject: [PATCH] Fix check for whether a dependency was built + improved mpw-bench output. --- MasterPassword/C/build | 7 ++++--- MasterPassword/C/mpw-bench.c | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/MasterPassword/C/build b/MasterPassword/C/build index 14a10cd1..5924aa7a 100755 --- a/MasterPassword/C/build +++ b/MasterPassword/C/build @@ -85,8 +85,7 @@ depend() { echo echo "Checking dependency $1..." - objects=( "lib/$1"/*.o ) - [[ -e $objects ]] && return + [[ -e "lib/$1/.built" ]] && return pushd "lib/$1" files=( * ) @@ -113,6 +112,7 @@ depend() { echo "Building dependency $1..." if [[ -e Makefile ]]; then make + date > .built else echo >&2 "error: Don't know how to build: $1" exit 1 @@ -125,6 +125,7 @@ depend() { mpw() { depend scrypt + echo echo "Building target: $target..." CFLAGS=( # include paths @@ -155,6 +156,7 @@ mpw-bench() { depend scrypt depend bcrypt + echo echo "Building target: $target..." CFLAGS=( # include paths @@ -198,6 +200,5 @@ cc() { } for target in "${targets[@]}"; do - echo "$target" "$@" done diff --git a/MasterPassword/C/mpw-bench.c b/MasterPassword/C/mpw-bench.c index bbf218be..77550b17 100644 --- a/MasterPassword/C/mpw-bench.c +++ b/MasterPassword/C/mpw-bench.c @@ -110,7 +110,8 @@ int main(int argc, char *const argv[]) { } memset(sitePasswordSeed, 0, sizeof(sitePasswordSeed)); - fprintf( stderr, "\riteration %d / %d..", i, iterations ); + if (i % 1 == 0) + fprintf( stderr, "\rmpw: iteration %d / %d..", i, iterations ); } // Output timing results. @@ -122,7 +123,8 @@ int main(int argc, char *const argv[]) { long long secs = (endTime.tv_sec - startTime.tv_sec); long long usecs = (endTime.tv_usec - startTime.tv_usec); double elapsed = secs + usecs / 1000000.0; - fprintf( stdout, "Master Password: %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, iterations / elapsed ); + double mpwSpeed = iterations / elapsed; + fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, mpwSpeed ); // Start SHA-256 if (gettimeofday(&startTime, NULL) != 0) { @@ -134,7 +136,9 @@ int main(int argc, char *const argv[]) { uint8_t hash[32]; for (int i = 0; i < iterations; ++i) { SHA256_Buf(masterPassword, strlen(masterPassword), hash); - fprintf( stderr, "\riteration %d / %d..", i, iterations ); + + if (i % 1000 == 0) + fprintf( stderr, "\rsha256: iteration %d / %d..", i, iterations ); } // Output timing results. @@ -145,7 +149,8 @@ int main(int argc, char *const argv[]) { secs = (endTime.tv_sec - startTime.tv_sec); usecs = (endTime.tv_usec - startTime.tv_usec); elapsed = secs + usecs / 1000000.0; - fprintf( stdout, "SHA-256: %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, iterations / elapsed ); + double sha256Speed = iterations / elapsed; + fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, sha256Speed ); // Start BCrypt if (gettimeofday(&startTime, NULL) != 0) { @@ -157,7 +162,9 @@ int main(int argc, char *const argv[]) { iterations = 600; for (int i = 0; i < iterations; ++i) { crypt(masterPassword, crypt_gensalt("$2b$", bcrypt_cost, userName, strlen(userName))); - fprintf( stderr, "\riteration %d / %d..", i, iterations ); + + if (i % 10 == 0) + fprintf( stderr, "\rbcrypt (cost %d): iteration %d / %d..", bcrypt_cost, i, iterations ); } // Output timing results. @@ -168,7 +175,13 @@ int main(int argc, char *const argv[]) { secs = (endTime.tv_sec - startTime.tv_sec); usecs = (endTime.tv_usec - startTime.tv_usec); elapsed = secs + usecs / 1000000.0; - fprintf( stdout, "BCrypt (cost %d): %d iterations in %llds %lldµs -> %.2f/s\n", bcrypt_cost, iterations, secs, usecs, iterations / elapsed ); + double bcrypt9Speed = iterations / elapsed; + fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, bcrypt9Speed ); + + // Summarize. + fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" ); + fprintf( stdout, "mpw is %f times slower than sha256\n", sha256Speed / mpwSpeed ); + fprintf( stdout, "mpw is %f times slower than bcrypt (cost 9)\n", bcrypt9Speed / mpwSpeed ); return 0; }