/* Sumloop Applet @Author: Christopher Hylands, based on Prime.java by Tom Parks @Version:@(#)SumloopApplet.java 1.3 02/05/98 @Copyright (c) 1998 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ import java.applet.Applet; import java.awt.*; import ptplot.*; ////////////////////////////////////////////////////////////////////////// //// sumloopApplet /** * Applet interface to Kernighan and Wyk's sumloop class. */ public class SumloopApplet extends TextPlotApplet { /** Add a point to the plot. This method is called by JavaScript. */ public void addPoint(int dataset, double x, double y, boolean connected) { timeplot.addPoint(dataset, x, y, connected); } /** Initialize the plot */ public void init() { timeplot = new Plot(); timeplot.setYLog(true); timeplot.setXRange(125000,1000000); timeplot.setYRange(-2,2); timeplot.setTitle("Sumloop"); timeplot.setNumSets(2); timeplot.setXLabel("n"); timeplot.setYLabel("seconds"); timeplot.setMarksStyle("various"); timeplot.addLegend(0, "JavaScript"); timeplot.addLegend(1, "Java Applet"); super.init(); } /** Return a string describing this applet. */ public String getAppletInfo() { return "SumloopApplet: Applet interface to Kernighan & Wyk's " + "sumloop timing tests\n" + "By: Christopher Hylands, cxh@eecs.berkeley.edu\n" + "@(#)SumloopApplet.java 1.3 02/05/98"; } /** * Run the all the tests. * This method is called when the button is pressed. */ public void runTest () { _frame.setCursor(Frame.WAIT_CURSOR); int loops = 0; try { loops = Integer.parseInt(_loopField.getText()); } catch (NumberFormatException e) {} output.appendText("loop: "+loops); _connected = false; runOneTest(loops, 125000); runOneTest(loops, 250000); runOneTest(loops, 500000); runOneTest(loops, 1000000); _connected = false; _frame.setCursor(Frame.DEFAULT_CURSOR); } /** Run one test, plot the data */ public void runOneTest (int loops, int n) { String argv[] = new String[1]; argv[0] = String.valueOf(n); String results; for(int i = 0; i