No Tigger here yet (on order through the university)...
Could someone please test the following code and see how it runs? Just
adjust the properties (if you want), dock/undock it or resize it a few
times and see what happens.
Thanks! Are Tiggers wunnerful things? :-)
Craig
/**
Program: Butterfly.java
Author : Craig Mattocks <mattocks AT mac D0T com>
Date : July, 2004
Description: Draws a 4-petal rose in polar coordinates
to test line drawing performance in Java.
drawLine vs. drawPolyline
To test Shark
-------------
Compile:
javac -g Butterfly.java
Run:
java -XrunShark -Xnoclassgc Butterfly &
2004-07-10 19:44:03.226 java[442] Shark for Java is enabled...
Capture session with Shark via command line:
shark -1 -i -a 442
*/
/**
* Butterfly class
*/
public class Butterfly extends JFrame
{
/**
* static initialization block to set properties
*/
static
{
// System.setProperty("com.apple.hwaccel", "true");
// System.setProperty("apple.awt.graphics.EnableQ2DX", "true");
/**
* Description: Use a queue for graphics primtives
* (improves graphics performance of rendering simple
* primtives - lines, rects, arcs, ovals).
* Default Value: true
*/
System.setProperty("apple.awt.graphics.EnableLazyDrawing", "true");
/**
* Description: Controls the size of a queue used by
* EnableLazyDrawing optimization (in entries, where 1
* entry = 4 bytes). One graphics primitive requires
* about 10 entries.
* Default Value: 2
*/
System.setProperty("apple.awt.graphics.EnableLazyDrawingQueueSize",
"16");
}
/**
* Class instance vars
*/
// Plot parameters
private static final int POINTS = 4000;
private static final double PERIOD = 360d/POINTS;
private static final int SCALE = 500;
private int x[];
private int y[];
// Dimensions of frame
private static final int WIDTH = SCALE,
HEIGHT = SCALE;
private Insets insets;
private Dimension size;
// CPU timing variables
private HiResTimer timer;
private long before, after, cpuTime;
// Number formatting
NumberFormat digits = NumberFormat.getInstance();
/**
* Initialize some data for the plot:
* the NCAR graphics "butterfly" -
* a 4-petal rose in polar coordinates.
*/
double theta, rho;
x = new int[POINTS];
y = new int[POINTS];
JPanel panel = new JPanel()
{
/**
* Override paintComponent method for custom drawing
*/
public void paintComponent(final Graphics g)
{
// Draw lines one at a time
g.setColor(Color.blue);
cpuTime = timer.nanoTime();
for (int i=0; i<POINTS-1; i++)
g.drawLine(x[i],y[i], x[i+1],y[i+1]);
before = timer.nanoTime() - cpuTime;
g.drawString("Time for Lines is " + before + " nanoseconds",
10,15);
System.out.println("Time for Lines is " + before + "
nanoseconds");
/**
g.clearRect
(
insets.left,
insets.top,
size.width - insets.left - insets.right,
size.height - insets.top - insets.bottom
);
*/
// Draw multiple lines at once
g.setColor(Color.red);
cpuTime = timer.nanoTime();
g.drawPolyline(x,y, POINTS);
after = timer.nanoTime() - cpuTime;
g.drawString("Time for Polyline is " + after + " nanoseconds",
10,30);
System.out.println("Time for Polyline is " + after + "
nanoseconds");
//////////
// main //
//////////
public static void main(final String args[])
{
final Butterfly app = new Butterfly();
SwingUtilities.invokeLater
(
new Runnable()
{
public void run()
{
centerWindow(app);
app.setVisible(true);
}
}
);
}
/**
* Inner class for high-rez timing measurements.
* Substitute for JDK 5 System.nanoTime()
*/
public class HiResTimer
{
/**
* Class instance vars
*/
private Perf hiResTimer;
private long freq;
/**
* return current time in nanoseconds
*/
public long nanoTime()
{
return (hiResTimer.highResCounter() * 1000000000L/freq);
}
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden