Форум: "Потрепаться";
Текущий архив: 2002.04.04;
Скачать: [xml.tar.bz2];
ВнизСравнение компиляторов - часть 2 Найти похожие ветки
← →
iZEN (2002-02-20 18:43) [67]Итак, тест быстродействия Java2 (SunJRE/JDK1.4).
package test;
/**
* Title: Тестовые вычисления
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author iZEN
* @version 1.0
*/
import java.util.*;
import java.io.*;
public class TestApplication {
protected static void printProperties(PrintStream out, String[] keys) {
int i = 0;
try {
for (i = 0; i < keys.length; i++) out.println(keys[i] + "=" + "\"" + System.getProperty(keys[i]) + "\"" + ";");
} catch(SecurityException sex) {
out.println(keys[i] + ": нет доступа к свойству");
}
}
public static final String[] JVM_PROPERTY_NAMES = {"java.vm.name", "java.vm.vendor", "java.vm.version"};
public static void printJVMProperties(PrintStream out) {
printProperties(out, JVM_PROPERTY_NAMES);
}
public static void printAllProperties(PrintStream out) {
Vector keys = new Vector();
try {
Properties p = System.getProperties();
Enumeration e = p.propertyNames();
while(e.hasMoreElements())
try {
String key = new String((String)e.nextElement());
keys.add(key);
} catch (SecurityException nosex) {//Не обрабатывается
}
} catch (NoSuchElementException nonseex) {//Не обрабатывается
}
String[] allkeys = new String[keys.size()];
for(int i = 0; i < keys.size(); i++) allkeys[i] = (String)keys.elementAt(i);
printProperties(out, allkeys);
}
/**
* Исходный код на ObjectPascal:
*
* function FloatTest(iInitVal: Integer): double;
* var
* f0, f1, f2, f3 : double;
* i : Integer;
* begin
* f0 := 0;
* f1 := 123.456789;
* f2 := 98765.12345678998765432;
* f3 := 12345678943.98;
* for i := 1 To iInitVal - 1 do begin
* f0 := (f1 / i) - f2 + (f3 * i);
* end;
* result := f0;
* end;
*/
public static double floatTest(int iInitVal) {
double f0 = 0d;
double f1 = 123.456789d;
double f2 = 98765.12345678998765432d;
double f3 = 12345678943.98d;
for (int i = 1; i < iInitVal - 1; i++) {
f0 = (f1 / i) - f2 + (f3 * i);
}
return f0;
}
/**
* Генератор массива размером length со случайно распределённоыми значениями
* типа float
*/
public static float[] getRandomFloatArray(int length) {
float[] result = new float[length];
///Random r = new Random();
for(int i = 0; i < length; i++) result[i] = (float)Math.random() - 0.5f;///r.nextFloat();
return result;
}
/**
* Печать элементов массива
*/
public static void printFloatArray(PrintStream out, float[] arr, int from, int length) {
for(int i = from; i < from + length - 1; i++) out.print(arr[i] + ";");
out.println(arr[from + length - 1] + ".");
}
/**
* BubbleSort -- сортировка методом пузырька
*/
public static void bubbleSort(float[] data) {
float temp = 0;
for(int i = data.length; --i >= 0;) {
boolean swapped = false;
for(int j = 0; j < i; j++) {
if(data[j] > data[j+1]) {
temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
swapped = true;
}
}
if(!swapped) return;
}
}
/**Main method -- точка входа*/
public static void main(String[] args) {
long startTime, endTime, delay;
//System.out.println("System: ");
//printAllProperties(System.out);
System.out.println("JVM: ");
printJVMProperties(System.out);
System.out.println();
/* BubbleSort-тест -- cортировка методом пузырька */
int length = 100000;
float[] rfa = getRandomFloatArray(length);
System.out.println("BubbleSort-тест: cортировка методом пузырька " + length + " элементов типа float.");
System.out.print("До сортировки (часть данных): ");
printFloatArray(System.out, rfa, 9990, 10);
startTime = System.currentTimeMillis();
bubbleSort(rfa);
endTime = System.currentTimeMillis();
delay = endTime - startTime;
System.out.print("После сортировки (часть данных): ");
printFloatArray(System.out, rfa, 9990, 10);
System.out.println("Длительность BubleSort-теста (миллисекунды): " + delay);
System.out.println();
/* Float-тест */
int someValue = 1000000000;
System.out.println("Float-тест с начальным значением=" + someValue);
startTime = System.currentTimeMillis();
double someResult = floatTest(someValue);
endTime = System.currentTimeMillis();
delay = endTime - startTime;
System.out.println("Float-тест закончен, результат=" + someResult);
System.out.println("Длительность Float-теста (миллисекунды): " + delay);
System.out.println();
}
}
Страницы: 1 2 3 вся ветка
Форум: "Потрепаться";
Текущий архив: 2002.04.04;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.005 c