[Assorted-commits] SF.net SVN: assorted:[1397] rand-dist/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-07 07:46:36
|
Revision: 1397 http://assorted.svn.sourceforge.net/assorted/?rev=1397&view=rev Author: yangzhang Date: 2009-05-07 07:46:35 +0000 (Thu, 07 May 2009) Log Message: ----------- added randspeed to compare performance of rand impls Modified Paths: -------------- rand-dist/trunk/src/Makefile rand-dist/trunk/src/randdist.cc Added Paths: ----------- rand-dist/trunk/src/randspeed.cc Modified: rand-dist/trunk/src/Makefile =================================================================== --- rand-dist/trunk/src/Makefile 2009-05-07 07:44:39 UTC (rev 1396) +++ rand-dist/trunk/src/Makefile 2009-05-07 07:46:35 UTC (rev 1397) @@ -1,2 +1,2 @@ CFLAGS := -Wall -O3 -all: randdist +all: randdist randspeed Modified: rand-dist/trunk/src/randdist.cc =================================================================== --- rand-dist/trunk/src/randdist.cc 2009-05-07 07:44:39 UTC (rev 1396) +++ rand-dist/trunk/src/randdist.cc 2009-05-07 07:46:35 UTC (rev 1397) @@ -16,6 +16,8 @@ const int size = atoi(argv[1]); const int count = atoi(argv[2]); + posix_rand r; + vector<int> xs(size); for (int i = 0; i < count; i++) { xs[i] = r(); Added: rand-dist/trunk/src/randspeed.cc =================================================================== --- rand-dist/trunk/src/randspeed.cc (rev 0) +++ rand-dist/trunk/src/randspeed.cc 2009-05-07 07:46:35 UTC (rev 1397) @@ -0,0 +1,29 @@ +#include <commons/rand.h> +#include <commons/time.h> +#include <iostream> +using namespace commons; +using namespace std; + +int count; + +template<typename T> +void exp(T r, const string &name) +{ + int x = 0; + long long start = current_time_millis(); + for (int i = 0; i < count; ++i) x |= r(); + long long diff = current_time_millis() - start; + cout << name << ": " << diff << " ms or " + << 1000 * count / double(diff) << " r/s; " << hex << x << endl; +} + +int main(int argc, char **argv) { + if (argc < 2) { + cerr << "randspeed COUNT" << endl; + return 1; + } + count = atoi(argv[1]); + exp(posix_rand(), "posix_rand"); + exp(&random, "random"); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |