double rate,sum; int n; Stopwatch sw = new Stopwatch(); for (int niter=0; niter<5; ++niter) { sw.restart(); for (n=0; sw.time()<maxtime; ++n) filter1(b0,b1,b2,a1,a2,x,y); sw.stop(); sum = sum(y); rate = n*mflop/sw.time(); System.out.println("filter1: rate="+rate+" sum="+sum); sw.restart(); for (n=0; sw.time()<maxtime; ++n) filter2a(b0,b1,b2,a1,a2,x,y); sw.stop(); sum = sum(y); rate = n*mflop/sw.time(); System.out.println("filter2a: rate="+rate+" sum="+sum); sw.restart(); for (n=0; sw.time()<maxtime; ++n) filter2b(b0,b1,b2,a1,a2,x,y); sw.stop(); sum = sum(y); rate = n*mflop/sw.time(); System.out.println("filter2b: rate="+rate+" sum="+sum);
public void glInit() { makeQuads(65536); glClearColor(0.0f,0.0f,0.0f,0.0f); glEnable(GL_DEPTH_TEST); _stopwatch.start(); } public void glResize(int x, int y, int width, int height) {
/** * Stops this stopwatch and resets the time to zero. */ public void reset() { stop(); _time = 0; }
public void glInit() { glClearColor(0.0f,0.0f,0.0f,0.0f); glEnable(GL_DEPTH_TEST); listCircleInit(_nsides); _stopwatch.start(); } public void glResize(int x, int y, int width, int height) {
private static double time(int nfft) { double maxtime = 2.0; FftComplex fft = new FftComplex(nfft); float[] cx = crandfloat(nfft); int count; Stopwatch sw = new Stopwatch(); sw.start(); for (count=0; sw.time()<maxtime; ++count) { fft.complexToComplex(-1,cx,cx); fft.complexToComplex( 1,cx,cx); fft.scale(nfft,cx); } sw.stop(); double time = sw.time()/(float)count; return time; } }
float[][] c4 = zerofloat(m,m); float[][] c5 = zerofloat(m,m); Stopwatch s = new Stopwatch(); double mflops = 2.0e-6*m*m*n; double maxtime = 5.0; s.restart(); for (nmul=0; s.time()<maxtime; ++nmul) mul1(a,b,c1); s.stop(); System.out.println("mul1: rate="+(int)(nmul*mflops/s.time())+" mflops"); s.restart(); for (nmul=0; s.time()<maxtime; ++nmul) mul2(a,b,c2); s.stop(); System.out.println("mul2: rate="+(int)(nmul*mflops/s.time())+" mflops"); s.restart(); for (nmul=0; s.time()<maxtime; ++nmul) mul3(a,b,c3); s.stop(); System.out.println("mul3: rate="+(int)(nmul*mflops/s.time())+" mflops"); s.restart(); for (nmul=0; s.time()<maxtime; ++nmul) mul4(a,b,c4); s.stop(); System.out.println("mul4: rate="+(int)(nmul*mflops/s.time())+" mflops");
private static void benchFloat( ArrayFile af, int n) throws IOException { float[] a = randfloat(n); float[] b = zerofloat(n); int nio; Stopwatch sw = new Stopwatch(); sw.start(); for (nio=0; sw.time()<5.0; ++nio) { af.seek(0); af.writeFloats(a); af.seek(0); af.readFloats(b); } sw.stop(); for (int i=0; i<n; ++i) if (a[i]!=b[i]) throw new RuntimeException(" float: i/o failure"); double time = sw.time(); double rate = 2.0*4.0e-6*nio*n/time; System.out.println(" float: rate="+rate+" MB/s"); }
Stopwatch sw = new Stopwatch(); int nh = 60; // like a trace header int na = 1000; // like trace samples new ArrayOutputStream(new BufferedOutputStream(fos)) : new ArrayOutputStream(fos); sw.restart(); for (nw=0,s=0.0; sw.time()<maxtime; ++nw) { s += sum(a); aos.writeInts(h); sw.stop(); rate = (int)(mbytes*nw/sw.time()); System.out.println("ArrayOutputStream: sum="+s+" nw="+nw+" rate="+rate); FileInputStream fis = new FileInputStream(file); new ArrayInputStream(new BufferedInputStream(fis)) : new ArrayInputStream(fis); sw.restart(); for (nr=0,s=0.0; nr<nw; ++nr) { ais.readInts(h); sw.stop(); rate = (int)(mbytes*nr/sw.time()); System.out.println(" ArrayInputStream: sum="+s+" nr="+nr+" rate="+rate);
private static void benchDouble( ArrayFile af, int n) throws IOException { double[] a = randdouble(n); double[] b = zerodouble(n); int nio; Stopwatch sw = new Stopwatch(); sw.start(); for (nio=0; sw.time()<5.0; ++nio) { af.seek(0); af.writeDoubles(a); af.seek(0); af.readDoubles(b); } sw.stop(); for (int i=0; i<n; ++i) if (a[i]!=b[i]) throw new RuntimeException("double: i/o failure"); double time = sw.time(); double rate = 2.0*8.0e-6*nio*n/time; System.out.println("double: rate="+rate+" MB/s"); } }
public static void bench() { Random r = new Random(); RandomFloat rf = new RandomFloat(); Stopwatch sw = new Stopwatch(); int nf; float sum; sw.restart(); sum = 0.0f; for(nf=0; sw.time()<1.0; ++nf) sum += r.nextFloat(); sw.stop(); rate = nf/sw.time(); System.out.println(" uniform: float/s="+rate+" sum="+sum); sw.restart(); sum = 0.0f; for(nf=0; sw.time()<1.0; ++nf) sum += (float)r.nextGaussian(); sw.stop(); rate = nf/sw.time(); System.out.println(" normal: float/s="+rate+" sum="+sum); sw.restart(); sum = 0.0f; for(nf=0; sw.time()<1.0; ++nf) sum += rf.uniform(); sw.stop(); rate = nf/sw.time(); System.out.println(" uniform: float/s="+rate+" sum="+sum); sw.restart();
Stopwatch sw = new Stopwatch(); for (int niter=0; niter<5; ++niter) { sw.restart(); for (nqrd=0; sw.time()<maxtime; ++nqrd) { qrd1 = new edu.mines.jtk.la.DMatrixQrd(aj); x1 = qrd1.solve(bj); sw.stop(); sum = sum(x1.getArray()); rate = nqrd/sw.time(); System.out.println("edu.mines.jtk.la: rate="+rate+" sum="+sum); sw.restart(); for (nqrd=0; sw.time()<maxtime; ++nqrd) { qrd2 = new edu.mines.jtk.lapack.DMatrixQrd(al); x2 = qrd2.solve(bl); sw.stop(); sum = sum(x2.getArray()); rate = nqrd/sw.time(); System.out.println("edu.mines.jtk.lapack: rate="+rate+" sum="+sum);
double mflop2 = 1.0e-6*n1*n2; double mflop3 = 1.0e-6*n1*n2*n3; Stopwatch sw = new Stopwatch(); float[][][] a = sub(randfloat(n1,n2,n3),0.5f); for (int ntest=0; ntest<3; ++ntest) { float ss = 0.0f; float sp = 0.0f; sw.restart(); for (niter=0; sw.time()<maxtime; ++niter) ss = sumS(a[0]); sw.stop(); rate = (int)((niter*mflop2)/sw.time()); System.out.println("2D S: rate = "+rate); sw.restart(); for (niter=0; sw.time()<maxtime; ++niter) sp = sumP(a[0]); sw.stop(); rate = (int)((niter*mflop2)/sw.time()); System.out.println("2D P: rate = "+rate); sw.restart(); for (niter=0; sw.time()<maxtime; ++niter) ss = sumS(a); sw.stop(); rate = (int)((niter*mflop3)/sw.time()); System.out.println("3D S: rate = "+rate); sw.restart(); for (niter=0; sw.time()<maxtime; ++niter) sp = sumP(a);