Oi,
Original em C (usando LCC : http://www.cs.virginia.edu/~lcc-win32/ )
// -----------------------------------
#include <windows.h>
#include <math.h>
#include <stdio.h>
#define MAX 100000
int main() {
DWORD start[5],finish[5];
float result = 0;
for (int a = 0; a < 5; a ++) {
start[a] = GetTickCount();
for (long j = 0; j < 200; j++) {
for (double i = 1; i < MAX; i = i + 1.0) {
result *= i / sqrt (i);
}
}
finish[a] = GetTickCount();
}
DWORD media = 0;
for (int a = 0; a < 5; a++) {
media += finish[a]-start[a];
printf ("tempo gasto (%d) : %ldms \n",a, finish[a]-start[a]);
}
printf ("tempo medio : %ldms \n", media / 5);
return 0;
}
// -----------------------------------
Em Java (JDK 1.4) :
/*
* TesteFloatPoint.java
*
* Created on 14 de Abril de 2002, 22:24
*/
/**
*
* @author xfer
*/
public class TesteFloatPoint {
/** Creates a new instance of TesteFloatPoint */
public TesteFloatPoint() {
}
/**
* @param args the command line arguments
*/
public static final int MAX = 100000;
public static void main(String[] args) {
long[] start, finish;
start = new long[5];
finish = new long[5];
float result = 0;
for (int a = 0; a < 5; a ++) {
start[a] = System.currentTimeMillis();
for (int j = 0; j < 200; j++) {
for (double i = 1; i < MAX; i = i + 1.0) {
result *= i / Math.sqrt(i);
}
}
finish[a] = System.currentTimeMillis();
}
long media = 0;
for (int a = 0; a < 5; a++) {
media += finish[a]-start[a];
System.out.println("tempo gasto (" + a + ") : " +
(finish[a]-start[a]));
}
System.out.println("tempo medio : " + (media / 5));
}
}
// ----------------------------------------------------------------
C:\bin\testeFP>floatpoint
tempo gasto (0) : 5929ms
tempo gasto (1) : 5978ms
tempo gasto (2) : 5869ms
tempo gasto (3) : 6018ms
tempo gasto (4) : 5839ms
tempo medio : 5926ms
C:\bin\testeFP>java -cp . TesteFloatPoint
tempo gasto (0) : 2323
tempo gasto (1) : 2294
tempo gasto (2) : 2283
tempo gasto (3) : 2303
tempo gasto (4) : 2304
tempo medio : 2301
Maquina : Pentium III 800Mhz, com 512mb de RAM, rodando WinXP Home
Edition.
heheh, isso vai rolar discussao por um mes, aposto...
.: sourbox :.
----- Original Message -----
From: "Douglas Carvalho" <[EMAIL PROTECTED]>
To: "Java-List" <[EMAIL PROTECTED]>
Sent: Sunday, April 14, 2002 4:22 PM
Subject: [java-list] Performance calculo
> Quanto � performance, os gr�ficos s�o
> um pouco lentos em Java, mas e os c�lculos?
> Se eu quiser construir um programa que
> efetue muitos c�lculos de ponto flutuante, a
> performance em Java � aceit�vel? Em rela��o
> � performance em C++ (vamos considerar um
> aplicativo para console, que n�o utilize interface
> gr�fica) quantas vezes aprox seria pior ou melhor?
>
> Atenciosamente,
>
> Douglas Carvalho
>
>
------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usu�rios Java da Sucesu-SP
d�vidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------