giovedì 20 gennaio 2011

Java and performance, non è impossibile con gcj

Java è un buon linguaggio. Molto diffuso e ricco di documentazione e librerie.
La Java VM è molto lenta. Molto lenta. Mooooooooolto lenta.
Sono venuto così a contatto con gcj ovvero gcc per Java. Questo compilatore produce un file eseguibile esattamente come per C/C++.

A questo punto viene spontaneo fare un piccolo test di performance. Premetto che il test proposto non ha valenza assoluta.

Compiliamo questa classe.
public class MiaClass
{
public MiaClass()
{
}

public void print()
{
long startTime = System.currentTimeMillis();

callOperationToTime();

long endTime = System.currentTimeMillis();

long totalTime = endTime - startTime;

System.out.println("Time: " + totalTime);
}

private void callOperationToTime()
{
for(int i = 0; i < 10000; i++)
{
System.out.println(" ");
}
}
}

e successivamente richiamiamola da un semplice "main".

public class HelloWorld {

public static void main(String[] args) {
MiaClass c = new MiaClass();
c.print();
}

}


Questo codice compilato con gcj esegue le operazioni in 75ms mentre lanciato con la Java VM i millisecondi salgono a 291.

La mia macchina è un P8400 e Ubuntu 10.04.

6 commenti:

Anonimo ha detto...

Generally speaking, customer feedback based improvements made everything much easier to handle.

In contrast, the 5DIII exhibits no loss of fine detail at ISO 6400.
For more information, take a look at the Canon EOS 5D Mark 3
technologies explained.

Here is my web blog ... canon 5d mark iii

Anonimo ha detto...

Ronnie Williams is a staff writer for Wireless - Phone - Gallery - offering Latest and Discounted google nexus accessories (also known as wireless google nexus one accessories) and a
lot more accessories for Samsung, Blackberry, Apple, Nokia and Sony
Ericsson. Check out these top picks from the heavyweights in the tablet industry, Google, Amazon and, of course,
Apple. If you already have a Google Gmail account, you can add
that easily through your Google account settings.


Also visit my web site; google nexus 7

Anonimo ha detto...

Simply click on the program that you want to watch and
go directly to the channel it's playing on. Loading time from screen to screen can vary and at times seems like it may take longer than usual but overall performance is great. Twonky: Streams music, photos and videos to compatible devices in the home.

my blog post ... roku box

Anonimo ha detto...

In addition, Po - P (Picture over Picture) function allows CCTV monitor to display video from alarm channel without leaving the
viewing mode of the current image. If you are using a DSL modem, are tethering through
a cell phone, or are still on dial-up, you probably have a static
IP address, and will actually have to enter in information
to this device to get connected to the Internet. Many years in
the past the user had to write their programming code manually, using some cryptic codes.



Review my site; samsung chromebook review

Anonimo ha detto...

The Dell Streak packs in a 1GHz Snapdragon ARM-based processor made by Qualcomm, 5MP autofocus camera with dual LED flash, VGA front-facing camera, integrated 3G + Wi-Fi, Bluetooth, and a
micro - SD expansion slot for up to 32GB of storage.
Click "Edit" button to remove the unwanted area like backside, set brightness, contrast, saturation of Kodak video and apply special effects to
your Kodak video. Sources demonstrate that this newly designed solution designed to offer
a streamlined framework for enterprises to unfurl
mobile apps for Blackberry Play - Book tablet users within the organization.


Review my website - blackberry playbook

Anonimo ha detto...

This article will help you find the best tablet PC. 3 inches screen, there is 285 pixel in
one inch, it is also called ppi. They are Vodafone, Virgin, T-Mobile, Orange, O2 and Three.


My website - samsung galaxy tab