/* ------------------------------------------------------------- This applet does a crude test of floating-point speed. Custom classes: DumbFlops Steve Witham 1999.02.19: This was soon after I wrote it. Some wierd hacks for Windows Ms. IE. 1999.07.19: Made each call to paint() do one test then call repaint(), instead of running repeated tests in a single call to paint(). 1999.08.03: Added a sync() call. Don't yet know whether it tames Ms. WinIE. ------------------------------------------------------------- */ import java.applet.Applet; import java.util.*; import java.awt.*; public class DumbFlops extends Applet { private int reps; private boolean done; private double flops; public void init() { this.done = false; this.reps = 10000; this.flops = 0.0; this.repaint(); /* Ask someone to call my update--Does this help at all? */ /* update = clear (paint background) then call my paint. */ } private void drawsub( Graphics g ) { g.setColor( Color.yellow ); g.fillRect( 0, 0, 300, 80 ); g.setColor( Color.black ); g.drawString( " Starting " + this.reps + " reps...", 20, 20 ); if( this.done ) { g.drawString( " " + this.flops + " 'flop'/sec", 20, 40 ); g.drawString( " Done.", 20, 60 ); } else if( this.flops > 0.0 ) { g.drawString( " (guess: " + this.flops + " 'flop'/sec)", 20, 40); } Toolkit.getDefaultToolkit().sync(); } public void paint(Graphics g) { int i, reps; long t0, t1; double x, y, dur; this.drawsub( g ); if( !this.done ) { reps = this.reps; t0 = System.currentTimeMillis(); y = 0.0; for( i = 0; i < reps; i++ ) { x = i; y += x * x; } t1 = System.currentTimeMillis(); dur = ( t1 - t0 ) / 1000.0; if( dur > 0.5 ) { this.flops = 2.0 * reps / dur; } if( dur < 10 ) { this.reps = (int) ( this.reps * 15.0 / (dur + 1.0) ); } else { this.done = true; } this.repaint(); /* Remind me to paint again! */ } } }