FileDocCategorySizeDatePackage
ScaleChart.javaAPI DocExample3692Thu Feb 04 16:10:42 GMT 1999None

ScaleChart

public class ScaleChart extends Object implements Runnable

Fields Summary
protected int
numIter
Constructors Summary
Methods Summary
public voidchart()

		SimpleScheduler ss = new SimpleScheduler(100);
		ss.start();								 // Ensure Round Robin
		configure();								// Ensure Test Length
		try {
			double sIter = normalize(numIter, doLargeCalculation(1));
			System.out.println("\t" + 1 + "\t" + sIter + "\t" + 1.00);
			for (int i = 2;; i++) {
				double nIter = normalize((numIter * i), doLargeCalculation(i));
				System.out.println("\t" + i + "\t" + nIter + "\t" + (nIter/sIter));
			}
		} catch (Exception e) {
			System.out.println("Error: " + e);
		}
	
private voidconfigure()

		try {
			while(doLargeCalculation(1) < 60)
				numIter *= 2;
		} catch (Exception e) {
			System.out.println("Error: " + e);
		}
	
private longdoLargeCalculation(int numThreads)


	// Do large useless calculations in the number of threads
	//	 specified and return the number of seconds used.
	    
			  
		Vector tv = new Vector();
		int priority = Thread.currentThread().getPriority() - 1;

		for (int i = 0; i < numThreads; i++) {
			Thread th = new Thread(this);
			tv.addElement(th);
			th.setPriority(priority);
		}
		long startTime = System.currentTimeMillis();
		Enumeration e = tv.elements();
		while (e.hasMoreElements()) {
			((Thread)e.nextElement()).start();
		}
		e = tv.elements();
		while (e.hasMoreElements()) {
			((Thread)e.nextElement()).join();
		}
		return (System.currentTimeMillis() - startTime) / 1000;
	
public static voidmain(java.lang.String[] args)

		ScaleChart sc = new ScaleChart();
		sc.chart();
	
private doublenormalize(int iter, long time)

		return ((double)iter * 60.0 / (double)time);
	
public voidrun()

		float sinValue = 0.0f;
		for (int i = 0; i < numIter; i++) {
			for (int j = 0; j < 360*100; j++) {
				sinValue = (float)Math.sin((j % 360)*Math.PI/180.0);
				sinValue *= (float)j / 180.0f;
			}
		}