created mirror

This commit is contained in:
whatever
2026-09-14 20:19:29 -04:00
commit 6764738d92
600 changed files with 87187 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
/*
GraphBench.java
*
* Copyright (c) 2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Tuomas Lukka
*/
package org.gzigzag.benchmark;
import org.gzigzag.*;
import java.util.*;
import java.awt.*;
/** Benchmark various graphics stuff.
*/
public class GraphBench {
public static final String rcsid = "$Id: GraphBench.java,v 1.2 2001/04/01 11:38:49 tjl Exp $";
static private void p(String s) { System.out.println(s); }
final Frame frame = new Frame();
{
frame.setSize(100,100);
frame.show();
}
final Font font = new Font("SansSerif", Font.PLAIN, 18);
final FontMetrics fontmetrics = frame.getFontMetrics(font);
ZZBench b = new ZZBench();
/** To be overridden by subclasses.
* Some graphics implementations, notably Java2D, require
* setting flags or hints in the Graphics object to improve
* rendering. We abstract the flags in this routine
* which all the rendering tests call.
*/
public void setFlags(Graphics g) {
}
static final int X(int i) {
return 50 + (i % 3) * 10;
}
static final int Y(int i) {
return 50 + (i % 5) * 10;
}
static final Color c(int i) {
i %= 2;
if(i==0) return Color.blue;
else if(i==1) return Color.red;
else return Color.green;
}
Canvas c = new Canvas();
{
c.setSize(300,800);
frame.add(c);
frame.pack();
}
Image getImage(int w, int h) {
return c.createImage(w,h);
}
public void runRender(final Graphics g) {
g.setFont(font);
setFlags(g);
b.run(new Object[] {
"DRAWTEXT6", "",
new Runnable() {
int i = 0;
public void run() {
g.setColor(c(i));
g.drawString("abcdef", X(i), Y(i));
i++;
}
},
"DRAWTEXT20", "",
new Runnable() {
int i = 0;
public void run() {
g.setColor(c(i));
g.drawString("abcdefghijklmnopqrst", X(i), Y(i));
i++;
}
},
});
}
public void run() {
p("Into image 300x300");
runRender(getImage(300,300).getGraphics());
p("Direct");
runRender(c.getGraphics());
b.run(new Object[] {
"FNTMETR6", "FontMetrics",
new Runnable() {
public void run() {
int i = fontmetrics.stringWidth("abcdef"); } },
"FNTMETR20", "FontMetrics 20 chars",
new Runnable() {
public void run() {
int i = fontmetrics.stringWidth("abcdefghijklmnopqrst"); } },
});
}
public static void main(String[] argv) {
new GraphBench().run();
System.exit(0);
}
}

16
Modules/benchmark/README Normal file
View File

@@ -0,0 +1,16 @@
GZigZag Benchmarking module
This module contains various pieces of code that test relative speeds
of various operations. The point is
1) provide a good basic intuition of what is fast and slow in Java,
for purpose of choosing implementation methods
2) provide a test for different JVM's efficiency on different tasks
(there are surprising diffrences here)
3) provide a testbed for zigzag algorithms and possible extensions,
such as the constraint model where the feasibility from a speed
perspective can be studied without building the whole system.

View File

@@ -0,0 +1,100 @@
/*
ZZBench.java
*
* Copyright (c) 2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Tuomas Lukka
*/
package org.gzigzag.benchmark;
import org.gzigzag.*;
import java.util.*;
/** Test speeds of various simple java operations,
* provide a generic simple speed-test framework.
*/
public class ZZBench {
public static final String rcsid = "$Id: ZZBench.java,v 1.3 2001/04/01 11:38:49 tjl Exp $";
static private void p(String s) { System.out.println(s); }
public void runTest(String s, Runnable r) {
// Start it up so that the JIT is ready
for(int i=0; i<32; i++) r.run();
// run more and more until we get over 3 secs of time.
int nt = 20;
long diff = 0;
do {
long t0 = System.currentTimeMillis();
for(int i = nt; i >= 0; i--)
r.run();
long t1 = System.currentTimeMillis();
nt *= 2;
diff = t1 - t0;
} while(diff < 1500);
p(s+": "+nt+" iter, "+diff+" ms, per iter: "+
(long)(1000000 * diff / (float)nt) + " ns");
}
/** Run the given tests, time them and print out the results.
* Each test should be relatively fast to execute.
* @param tests Triplets of String, String, Runnable:
* first string is a unique ID for the test,
* second string a human-readable explanation (without newlines)
* and the Runnable is the test itself.
*/
public void run(Object[] tests) {
for(int i=0; i<tests.length; i+= 3) {
p("Running "+tests[i]+": "+tests[i+1]);
Runnable r = (Runnable)tests[i+2];
runTest((String)tests[i], r);
}
}
public static void main(String[] argv) {
ZZBench b = new ZZBench();
b.run(new Object[] {
"PUTHASH", "Put a string into a hash (same place)",
new Runnable() { Hashtable h = new Hashtable();
public void run() { h.put("foo", "foo"); } },
"PUTGETCASTHASH",
"Put, get and cast a string into a hash (same place)",
new Runnable() { Hashtable h = new Hashtable(); String s;
public void run() { h.put("foo", "foo");
s = (String)h.get("foo"); } },
"CREATE", "Create an object",
new Runnable() { Object o;
public void run() { o = new Object(); } },
"CREATE4I", "Create an object with four ints inside",
new Runnable() { Object o;
public void run() { o = new Object() {
int i1, i2, i3, i4;
}; } },
"EMPTY", "empty function",
new Runnable() { public void run() { } },
"INCRINT", "Increment a member integer",
new Runnable() { int i; public void run() { i++; } },
"ASSIGN", "assign a member to another",
new Runnable() { ZZBench o = new ZZBench(); ZZBench b;
public void run() { b = (ZZBench)o; } },
"CLSCAST", "Class-cast a member, store to another",
new Runnable() { Object o = new ZZBench(); ZZBench b;
public void run() { b = (ZZBench)o; } },
});
}
}

View File

@@ -0,0 +1,95 @@
/*
Java2DBench.java
*
* Copyright (c) 2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Tuomas Lukka
*/
package org.gzigzag.benchmark;
import org.gzigzag.*;
import java.util.*;
import java.awt.*;
/** Benchmark Java2D: antialiasing, rotation etc.
*/
public class Java2DBench extends GraphBench {
public static final String rcsid = "$Id: Java2DBench.java,v 1.2 2001/04/01 11:38:49 tjl Exp $";
static private void p(String s) { System.out.println(s); }
RenderingHints speedHints = new RenderingHints(null);
RenderingHints qualityHints = new RenderingHints(null);
{
speedHints.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_SPEED);
qualityHints.put(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
qualityHints.put(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
qualityHints.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
qualityHints.put(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_PURE);
}
int cur;
public void setFlags(Graphics g0) {
Graphics2D g = (Graphics2D)g0;
if(cur < 2) {
p("ROTATED");
g.rotate(0.5);
} else {
p("STRAIGHT");
}
switch(cur % 2) {
// case 0:
// p("NO HINTS");
// break;
case 0:
p("SPEED");
g.setRenderingHints(speedHints);
break;
case 1:
p("QUALITY");
g.setRenderingHints(qualityHints);
break;
}
}
int maxcase = 4;
public void run() {
p("Into image 300x300");
for(cur = 0; cur <= maxcase; cur++)
runRender(getImage(300,300).getGraphics());
p("Direct");
for(cur = 0; cur <= maxcase; cur++)
runRender(c.getGraphics());
}
public static void main(String[] argv) {
new Java2DBench().run();
System.exit(0);
}
}