Data Abstraction Penalty Benchmark for Java. Version 1.0
- By Argyn Kuketayev
- August 1, 2001
Guest Column
The Data Abstraction Penalty (DAP) Benchmark for Small Objects in Java
by Argyn Kuketayev
Data Abstraction Penalty Benchmark for Java. Version 1.0
/*
Data Abstraction Penalty Benchmark for Java. Version 1.0
Copyright (C) 2001 Argyn Kuketayev
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple PlaceSuite 330, Boston, MA 02111-1307, USA.
You may contact author on [email protected]
*/
package com.tripod.argynchik.benchmark;
import java.util.*;
/**
* Java Small Objects Abstraction Penalty Benchmark.
* @author: Argyn
*/
public class AbstractionPenalty {
public static int current_test;
public static double[] result_times;
public static int iterations = 1000;
public static int size = 2000;
public double[] data;
public java.lang.Double[] dataD;
public double init_value = java.lang.Math.atan(1)*4;
public SimpleDouble[] dataSD;
public AbstractionPenalty() {
data = new double[size];
dataD = new Double[size];
dataSD = new SimpleDouble[size];
for(int i = 0; i < size; i++){
data[i] = init_value;
dataD[i] = new Double(init_value);
dataSD[i] = new SimpleDouble(init_value);
}
}
public static Collection toCollection(Object[] a){
ArrayList ret = new ArrayList();
for(int i=0; i<a.length; i++){
ret.add(a[i]);
}
ret.trimToSize();
return ret;
}
/**
* Checks the sum of an array
*/
public void check(double result) {
if(result != size * init_value ) throw new RuntimeException("test " + current_test + " failed");
}
/**
* Starts the application.
* @param args an array of command-line arguments: iterations size
* main(iterations, size)
*/
public static void main(java.lang.String[] args) {
AbstractionPenalty bm;
if(args.length == 2){
iterations = Integer.parseInt(args[0]);
size = Integer.parseInt(args[1]);
}
System.out.println("Data Abstraction Penalty Benchmark for Java "+
"version 1.0, Copyright (C) 2001 Argyn Kuketayev\n" +
"Data Abstraction Penalty Benchmark for Java comes with " +
"ABSOLUTELY NO WARRANTY.\n" +
"This is free software, and you are welcome to redistribute it "+
"under certain conditions; \nfor details see The GNU General Public License.\n");
System.out.println("command-line arguments: iterations size. "+
" Default values: 10, 200000");
result_times = new double[20];
AbstractionPenalty ap = new AbstractionPenalty();
current_test = 0;
ap.test0();
ap.test001();
ap.test002();
ap.test011();
ap.test012();
ap.test021();
ap.test022();
ap.test101();
ap.test102();
ap.test111();
ap.test112();
ap.test121();
ap.test122();
summarize();
}
/**
* Print summary
*/
public static void summarize() {
System.out.println("========================================================");
System.out.println("# Data Abstraction Penalty for Small objects in Java. #");
System.out.println("========================================================");
System.out.println("Date: " + (new Date()).toString());
System.out.println("iterations: " + iterations + ", size: " + size);
System.out.println("\nIndividual test results:");
System.out.println("- first column: number of the test.");
System.out.println("- second column: absolute time.");
System.out.println("- third column: rate in million instructions per second.");
System.out.println("- fourth column: time ratio to test0.\n");
double millions = ((double)size * iterations)/1e6;
for(int i = 0; i < current_test; i++){
System.out.println(
i + ", " +
result_times[i] + ", " +
millions / result_times[i] + ", " +
result_times[i] / result_times[0]);
}
double gmean_times = 0;
double total_absolute_times = 0;
double gmean_rate = 0;
double gmean_ratio = 0;
for(int i = 0; i < current_test; i++){
total_absolute_times += result_times[i];
gmean_times += java.lang.Math.log(result_times[i]);
gmean_rate += java.lang.Math.log(millions/result_times[i]);
gmean_ratio += java.lang.Math.log(result_times[i]/result_times[0]);
}
System.out.println("\nGeometrical mean results:");
System.out.println("- time: "+java.lang.Math.exp(gmean_times/current_test)+" sec.");
System.out.println("- rate: "+java.lang.Math.exp(gmean_rate/current_test) +" Mips.");
System.out.println("\nTotal absolute time: " + total_absolute_times + " sec.");
System.out.println("\n\nAbstraction Penalty: " + java.lang.Math.exp(gmean_ratio/current_test) );
}
/**
* double[] array summator.
*/
public final void test0() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
for(int n = 0; n < size; n++) result += data[n];
// check(result);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* @return java.lang.Double
* @param op1 java.lang.Double
* @param op2 java.lang.Double
*/
public Double plus(Double op1, Double op2) {
return new Double(op1.doubleValue() + op2.doubleValue());
}
/**
* @return SimpleDouble
* @param op1 SimpleDouble
* @param op2 SimpleDouble
*/
public SimpleDouble plus(SimpleDouble op1, SimpleDouble op2) {
return new SimpleDouble(op1.doubleValue() + op2.doubleValue());
}
/**
* Double[] array summator.
*/
public final void test001() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
for(int n = 0; n < size; n++) result += dataD[n].doubleValue();
// check(result);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* SimpleDouble array summator.
* Creation date: (01/24/2001 22:27:56)
*/
public final void test002() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
for(int n = 0; n < size; n++) result += dataSD[n].doubleValue();
// check(result);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with custom iterator over Double[]
*/
public final void test011() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
DoubleIterator it = new DoubleIterator(dataD);
while(it.hasNext()) result += it.next().doubleValue();
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with custom iterator over SimpleDouble[]
*/
public final void test012() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
SimpleDoubleIterator it = new SimpleDoubleIterator(dataSD);
while(it.hasNext()) result += it.next().doubleValue();
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with iterator of Collection of Double objects.
*/
public final void test021() {
Collection c = new Vector(toCollection(dataD));
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
Iterator it = c.iterator();
while(it.hasNext()) result += ((Double)it.next()).doubleValue();
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with iterator of Collection of SimpleDouble objects.
*/
public final void test022() {
Collection c = new Vector(toCollection(dataSD));
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
double result = 0;
Iterator it = c.iterator();
while(it.hasNext()) result += ((SimpleDouble)it.next()).doubleValue();
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with custom iterator over Double[] and PLUS operator.
*/
public final void test111() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
Double result = new Double(0);
DoubleIterator it = new DoubleIterator(dataD);
while(it.hasNext()) result = plus(it.next(), result);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with custom iterator over SimpleDouble[] and PLUS operator.
*/
public final void test112() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
SimpleDouble result = new SimpleDouble(0);
SimpleDoubleIterator it = new SimpleDoubleIterator(dataSD);
while(it.hasNext()) result = plus(result, it.next());
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum SimpleDouble[] with PLUS operator.
*/
public final void test101() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
Double result = new Double(0);
for(int n = 0; n < size; n++) result = plus(dataD[n], result);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum SimpleDouble[] with PLUS operator.
*/
public final void test102() {
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
SimpleDouble result = new SimpleDouble(0);
for(int n = 0; n < size; n++) result = plus(result, dataSD[n]);
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with iterator of Collection of SimpleDouble objects and PLUS operator.
*/
public final void test121() {
Collection c = new Vector(toCollection(dataD));
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
Double result = new Double(0);
Iterator it = c.iterator();
while(it.hasNext()) result = plus(result, (Double)it.next());
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
/**
* Sum with Iterator of Collection of SimpleDouble objects and PLUS operator.
*/
public final void test122() {
Collection c = new Vector(toCollection(dataSD));
double start = System.currentTimeMillis();
for(int i = 0; i < iterations; i++){
SimpleDouble result = new SimpleDouble(0);
Iterator it = c.iterator();
while(it.hasNext()) result = plus(result, (SimpleDouble)it.next());
}
result_times[current_test++] = (System.currentTimeMillis() - start)/1000;
}
}
About the Author
Argyn Kuketayev is a Software Engineer with Ionidea in Virginia. He graduated from Karaganda State University with a degree in Physics. He may be reached at [email protected].