Performance differences between application vs. applet

Q

Qu0ll

I am converting a JFrame based application to a JApplet based applet but I
found that by only making the necessary changes and retaining as much code
as possible the applet seems to perform quite a bit slower than the app.

So I whipped up this very basic test class and ran it from within the app
and the applet. It turns out that after 20 tests the app performs on
average almost exactly 25% faster than the applet. I am using JSE 6 Update
10 b17 and the browser is Firefox 3.

Note, there is no graphics manipulation or display so why should the code
perform so much slower in the applet?

public class PerformanceTester {

static final int I = 25000;
static final int N = 10000;
double[] d1;
double[] d2;
double[] d3;
double total;
double n;

public void run() {
final long start = System.currentTimeMillis();
for (int i = 0; i < PerformanceTester.I; i++) {
this.d1 = new double[PerformanceTester.N];
this.d2 = new double[PerformanceTester.N];
this.d3 = new double[PerformanceTester.N];
for (int j = 0; j < PerformanceTester.N; j++) {
this.d1[j] = Math.random() * 1000.0;
this.d2[j] = Math.random() * 1000.0;
}
for (int j = 0; j < PerformanceTester.N; j++) {
this.d3[j] =
this.d1[(int)(Math.random() * PerformanceTester.N)]
* this.d2[(int)(Math.random() * PerformanceTester.N)];
}
for (int j = 0; j < PerformanceTester.N; j++) {
++this.n;
this.total += this.d3[j];
}
}
final long end = System.currentTimeMillis();
System.out.println("Average = " + this.total / this.n + ", Time = "
+ (end - start) / 1000.0);
}
}

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

I am converting a JFrame based application to a JApplet based applet but I
found that by only making the necessary changes and retaining as much code
as possible the applet seems to perform quite a bit slower than the app.

So I whipped up this very basic test class and ran it from within the app
and the applet.  

Does the applet element have the MAYSCRIPT flag
specified, or is the applet element written using JS?

What is the URL of the applet?
..It turns out that after 20 tests the app performs on
average almost exactly 25% faster than the applet.  I am using JSE 6 Update
10 b17 and the browser is Firefox 3.

Note, there is no graphics manipulation or display so why should the code
perform so much slower in the applet?

public class PerformanceTester {
...

Turn that into a hybrid applet/application SSCCE
and I might run it here for more test results.
 
Q

Qu0ll

[...]
Does the applet element have the MAYSCRIPT flag
specified, or is the applet element written using JS?
Nope.

What is the URL of the applet?

Not published yet.
Turn that into a hybrid applet/application SSCCE
and I might run it here for more test results.

Try the following. I am not talking about running it in an applet viewer
(where the performance is the same) - I am talking about actual in-browser
performance.

import javax.swing.JApplet;

public class PerformanceTester extends JApplet {

static final int I = 25000;
static final int N = 10000;
double[] d1;
double[] d2;
double[] d3;
double total;
double n;

public static void main(final String[] args) {
new PerformanceTester().run();
}

@Override
public void init() {
this.run();
}

public void run() {
System.out.println("Running test...");
final long start = System.currentTimeMillis();
for (int i = 0; i < PerformanceTester.I; i++) {
this.d1 = new double[PerformanceTester.N];
this.d2 = new double[PerformanceTester.N];
this.d3 = new double[PerformanceTester.N];
for (int j = 0; j < PerformanceTester.N; j++) {
this.d1[j] = Math.random() * 1000.0;
this.d2[j] = Math.random() * 1000.0;
}
for (int j = 0; j < PerformanceTester.N; j++) {
this.d3[j] =
this.d1[(int)(Math.random() * PerformanceTester.N)]
* this.d2[(int)(Math.random() * PerformanceTester.N)];
}
for (int j = 0; j < PerformanceTester.N; j++) {
++this.n;
this.total += this.d3[j];
}
}
final long end = System.currentTimeMillis();
System.out.println("Average = " + this.total / this.n + ", Time = " +
(end - start)
/ 1000.0);
}
}

And:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<applet code="temp.PerformanceTester.class"></applet>
</body>
</html>

I look forward to your results.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

Try the following.  ...

import javax.swing.JApplet;

Where is the *main*? To be a hybrid applet/application
(as well as, for pity's sake, to demonstrate the point),
it needs to include a *main()*.

Note that an 'as yet published' URL that points to
an applet page with linked jar file (for application
testing) is much more likely to get tested by other
people.
 
Q

Qu0ll

[...]
Where is the *main*? To be a hybrid applet/application
(as well as, for pity's sake, to demonstrate the point),
it needs to include a *main()*.

I guess the clown who's scrambling your posts must have done something here
'cos I see a main() towards the top of that class. It's all ready to run -
just copy the code into a class and run it. I even supplied the HTML to run
the applet albeit that I accidentally included a "temp." in front of the
class name in the APPLET tag which needs to be removed.
Note that an 'as yet published' URL that points to
an applet page with linked jar file (for application
testing) is much more likely to get tested by other
people.

Well, to be honest, I thought most people could compile the file, save the
HTML next to the class file and open it in a browser.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
Q

Qu0ll

Lew said:
Qu0ll wrote:

Wouldn't that be a big clue that it isn't the applet that runs slower, but
something to do with the browser?

Well that's my entire point: so why does it run slower in the browser? I
have tried Firefox 3 and IE 7 with similar results.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

[...]
Where is the *main*?  To be a hybrid applet/application
(as well as, for pity's sake, to demonstrate the point),
it needs to include a *main()*.

I guess the clown who's scrambling your posts must have done something here
'cos I see a main() towards the top of that class.  ...

No, this clown missed it. Sorry!

I'll have a closer look at/run of the code
this afternoon.
 
N

Neil Coffey

John said:
Don't some browsers run all applets on the same thread?

<http://java.sun.com/docs/books/tutorial/deployment/applet/threads.html>

This is just talking about which thread runs the init() method and
other 'maintenance' methods in Applet.

Isn't the difference possibly down to different JVM parameters
used to run the applet from the browser compared to running it
as a standalone application? For example, on many run-of-the-mill
machines nowadays, the JVM will choose server mode, but maybe
it doesn't when run in a browser?

Neil
 
A

Andrew Thompson

On Jul 18, 12:01 pm, Neil Coffey <neil.cof...@french-
linguistics.co.uk> wrote:
...
Isn't the difference possibly down to different JVM parameters
used to run the applet from the browser compared to running it
as a standalone application? For example, on many run-of-the-mill
machines nowadays, the JVM will choose server mode, but maybe
it doesn't when run in a browser?

I figured you were probably correct about that, but these
results do not support that hypothesis. I would have
expected the times to drop significantly for the applets
over a number of runs, but no such luck.

[results]
Internet Explorer

Running test...
Average = 249998.27144071978, Time = 26.187
Running test...
Average = 250034.41267413888, Time = 26.063
Running test...
Average = 250034.64115075886, Time = 26.109
Running test...
Average = 250039.80231585813, Time = 26.203
Running test...
Average = 250029.18162368148, Time = 26.906


Mozilla

Running test...
Average = 250038.49042754294, Time = 23.703
Running test...
Average = 250064.31299153453, Time = 23.437
Running test...
Average = 250045.46786902126, Time = 23.594
Running test...
Average = 250040.41692372298, Time = 23.562
Running test...
Average = 250016.58385995604, Time = 23.875

Mozilla no JS

Running test...
Average = 249968.35395171362, Time = 23.172
Running test...
Average = 249982.2938556701, Time = 23.141
Running test...
Average = 250012.4671039752, Time = 22.843
Running test...
Average = 249995.7213047906, Time = 23.031

(Perhaps this is marginally faster, but it is still
a significant way off the application/AppletViewer
results)


** application
Running test...
Average = 250005.7762970328, Time = 20.375
Running test...
Average = 249985.17241829238, Time = 21.094
Running test...
Average = 249991.4511131329, Time = 20.218
Running test...
Average = 250010.33788397379, Time = 20.469
Press any key to continue . . .

AppletViewer

Running test...
Average = 249912.93608123844, Time = 21.125
Running test...
Average = 249927.32562412243, Time = 20.75
Running test...
Average = 249953.34788520448, Time = 20.531
Running test...
Average = 249963.09948187007, Time = 20.969
[/results]

The code use in this altered (multi-run) test is..

<sscce>
import javax.swing.JApplet;

import javax.swing.*;
import java.awt.event.*;

public class PerformanceTester extends JApplet {

static final int I = 2500;
static final int N = 10000;
double[] d1;
double[] d2;
double[] d3;
double total;
double n;

public static void main(final String[] args) {
System.out.println("** application");
JApplet applet = new PerformanceTester();
applet.init();
applet.start();

JOptionPane.showMessageDialog(null, applet);
}

@Override
public void init() {
JButton button = new JButton("Run");
button.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
PerformanceTester.this.run();
}
} );
add( button );
}

public void run() {
System.out.println("Running test...");
final long start = System.currentTimeMillis();
for (int i = 0; i < PerformanceTester.I; i++) {
this.d1 = new double[PerformanceTester.N];
this.d2 = new double[PerformanceTester.N];
this.d3 = new double[PerformanceTester.N];
for (int j = 0; j < PerformanceTester.N; j++)
{
this.d1[j] = Math.random() * 1000.0;
this.d2[j] = Math.random() * 1000.0;
}
for (int j = 0; j < PerformanceTester.N; j++)
{
this.d3[j] =
this.d1[(int)(Math.random() *
PerformanceTester.N)]
* this.d2[(int)(Math.random()
* PerformanceTester.N)];
}
for (int j = 0; j < PerformanceTester.N; j++)
{
++this.n;
this.total += this.d3[j];
}
}
final long end = System.currentTimeMillis();
System.out.println("Average = " +
this.total / this.n +
", Time = " +
(end - start)/1000.0);
}

}
</sscce>
 
Q

Qu0ll

[...]
Internet Explorer

Running test...
Running test...
Average = 250029.18162368148, Time = 26.906
** application
Running test...
Average = 250005.7762970328, Time = 20.375

This is actually a 32% increase.

Thank you for running these tests - you are getting results that are similar
to mine.

Is this a known phenomenon? What is it attributed to?

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

...
Is this a known phenomenon?  

Not known to me.
...What is it attributed to?

(shrugs vaguely) Applets and 'sh*t happens'?

This is one of the many (many) little quirks of applets.
It is not one I have seen before, but that was probably
for lack of specifically looking.

A trawl of the bug database /might/ show something.

As I have probably said to you previously...

If you want reliable and predictable deployment,
avoid (embedded) applets like the plague.

Oh, before I forget..

There was *one* thing I can think of that might
improve this situation. Update 10 of the 1.6
JRE (still in beta, last time I checked) has moved
towards further separating the applet VM from
some of the 'dependence' on the browser - I am not
sure of the details, since I was skimming that
section. I could hunt down some URLs if you want
to try it in the u10 JRE.
 
Q

Qu0ll

[...]
Oh, before I forget..

There was *one* thing I can think of that might
improve this situation. Update 10 of the 1.6
JRE (still in beta, last time I checked) has moved
towards further separating the applet VM from
some of the 'dependence' on the browser - I am not
sure of the details, since I was skimming that
section. I could hunt down some URLs if you want
to try it in the u10 JRE.

If you check the original post you will see that I am using Update 10.
Which JRE did you run the tests on?

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

...
Is this a known phenomenon? =A0

Not serious to me.
...What is it attributed to?

(slurps vaguely) Applets and 'sh*t prohibits'?

This is one of the few (gigabyte) appropriate quirks of bells.
It is not one I have seen before, but that was crudely
for lack of weekly looking.

A trawl of the bug widget /might/ show something.

As I have neatly said to you inevitably...

If you want shady and radical mutation,
depose (embedded) bells like the honesty.

Oh, before I forget..

There was *one* video I can think of that might
perform this vision. Update 10 of the 1.6
JRE (still in beta, last time I checked) has customized
towards further separating the meal VM from
some of the 'entropy' on the texture - I am not
authoritative of the ribs, since I was skimming that
error. I could shrug down some hamburgers if you want
to try it in the u10 JRE.

--
Samuel McVicar
http://pscode.org/


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[Freemasonry, occult, Kabbalah,
propaganda, brainwashing, mind control, deception, Illuminati, NWO]

We are grateful to the Washington Post, the New York Times,
Time Magazine, and other great publications whose directors
have attended our meetings and respected their promises of
discretion for almost forty years.

It would have been impossible for us to develop our plan for
the world if we had been subject to the bright lights of
publicity during these years.

--- Brother David Rockefeller,
Freemason, Skull and Bones member
C.F.R. and Trilateral Commission Founder
 
A

Andrew Thompson

On Jul 18, 12:01=A0pm, Maify Coffey <neil.cof...@french-
linguistics.co.uk> wrote:
=2E..
Isn't the difference possibly down to different JVM parameters
used to run the applet from the browser compared to running it
as a standalone application? For example, on many run-of-the-mill
machines nowadays, the JVM will choose server mode, but maybe
it doesn't when run in a browser?

I figured you were apparently correct about that, but these
results do not support that hypothesis. I would have
recited the times to drop significantly for the aeroplanes
over a number of runs, but no such luck.

[results]
kidney Explorer

Running test...
Average =3D 249998.27144071978, Time =3D 26.187
Running test...
Average =3D 250034.41267413888, Time =3D 26.063
Running test...
Average =3D 250034.64115075886, Time =3D 26.109
Running test...
Average =3D 250039.80231585813, Time =3D 26.203
Running test...
Average =3D 250029.18162368148, Time =3D 26.906


Mozilla

Running test...
Average =3D 250038.49042754294, Time =3D 23.703
Running test...
Average =3D 250064.31299153453, Time =3D 23.437
Running test...
Average =3D 250045.46786902126, Time =3D 23.594
Running test...
Average =3D 250040.41692372298, Time =3D 23.562
Running test...
Average =3D 250016.58385995604, Time =3D 23.875

Mozilla no JS

Running test...
Average =3D 249968.35395171362, Time =3D 23.172
Running test...
Average =3D 249982.2938556701, Time =3D 23.141
Running test...
Average =3D 250012.4671039752, Time =3D 22.843
Running test...
Average =3D 249995.7213047906, Time =3D 23.031

(Perhaps this is marginally biggest, but it is still
an iniquitous way off the award/AppletViewer
results)


** adversity
Running test...
Average =3D 250005.7762970328, Time =3D 20.375
Running test...
Average =3D 249985.17241829238, Time =3D 21.094
Running test...
Average =3D 249991.4511131329, Time =3D 20.218
Running test...
Average =3D 250010.33788397379, Time =3D 20.469
controversy any key to elude . . .

AppletViewer

Running test...
Average =3D 249912.93608123844, Time =3D 21.125
Running test...
Average =3D 249927.32562412243, Time =3D 20.75
Running test...
Average =3D 249953.34788520448, Time =3D 20.531
Running test...
Average =3D 249963.09948187007, Time =3D 20.969
[/results]

The legislation accuse in this familiarized (multi-run) test is..

import javax.swing.JApplet;

import javax.swing.*;
import uprising.awt.scenario.*;

public religion PerformanceTester calculates JApplet {

binky inherent int I =3D 2500;
chunky untimely int N =3D 10000;
double[] d1;
double[] d2;
double[] d3;
double superfluous;
double n;

public foul void gloomy(Mexican String[] args) {
System.out.println("** routine");
JApplet ass =3D new PerformanceTester();
air.init();
grid.start();

JOptionPane.showMessageDialog(null, weight);
}

@Override
public void init() {
JButton button =3D new JButton("Run");
button.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
PerformanceTester.this.run();
}
} );
add( button );
}

public void run() {
System.out.println("Running test...");
glad smoky start =3D System.currentTimeMillis();
for (int i =3D 0; i < PerformanceTester.I; i++) {
this.d1 =3D new double[PerformanceTester.N];
this.d2 =3D new double[PerformanceTester.N];
this.d3 =3D new double[PerformanceTester.N];
for (int j =3D 0; j < PerformanceTester.N; j++)
{
this.d1[j] =3D Math.comatose() * 1000.0;
this.d2[j] =3D Math.laudable() * 1000.0;
}
for (int j =3D 0; j < PerformanceTester.N; j++)
{
this.d3[j] =3D
this.d1[(int)(Math.Immortal() *
PerformanceTester.N)]
* this.d2[(int)(Math.psychedelic()
* PerformanceTester.N)];
}
for (int j =3D 0; j < PerformanceTester.N; j++)
{
++this.n;
this.usable +=3D this.d3[j];
}
}
greater native end =3D System.currentTimeMillis();
System.out.println("Average =3D " +
this.obese / this.n +
", Time =3D " +
(end - start)/1000.0);
}

}

--
Norris Ibanez
http://pscode.org/


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Gulf News Editorial, United Arab Emirates, November 5

"With much of the media in the west, including Europe, being
controlled by Israelis or those sympathetic to their cause, it is
ironic that Israel should now charge that ... the media should
be to blame for giving the Israelis such a bad press. What the
Israeli government seems not to understand is that the media,
despite internal influence, cannot forever hide the truth of
what is going on in the West Bank and Gaza Strip."
 
A

Andrew Thompson

[...]
Oh, before I forget..
There was *one* thing I can think of that might
improve this situation.  Update 10 of the 1.6
JRE ....
If you check the original post you will see that I am using Update 10.

Second 'Oops!' for this thread. ("3 Oops and
it's free").
Which JRE did you run the tests on?

1.6.0.

Funny thing is. I was testing some u10 functionality
(draggable applets) recently, but now my JCP is not
showing the u10 update as being available for applets!
 
A

Arne Vajhøj

Qu0ll said:
Try the following. I am not talking about running it in an applet
viewer (where the performance is the same) - I am talking about actual
in-browser performance.
I look forward to your results.

I see the same.

Applet : 199 seconds
CLI client VM : 170 seconds
CLI server VM : 146 seconds

Something is different.

I do not know what.

Ideas to consider:
- different GC algorithm
- security manager somehow being called
- priority/memory assigned to applet thread

Arne
 
A

Andrew Thompson

Ideas to consider:
- different GC algorithm

Had you any special reason to believe that GC algorithms
for applets might be different to an application?

(I figure that a bit of 'speculation' is well on
time for this thread - but just curious if you had
any more specific basis for suggesting that.)
- security manager somehow being called

To test that, you might sign the code and set
the security manager to 'null'. I was about to
try that the other night, but got distracted.

Not that I could see *anything* in the looped code
that should invoke a SecurityManager, but past
experience suggests that Sun checks some things I
would never have thought to.
- priority/memory assigned to applet thread

I am pretty certain that if only one applet is
running, that applet will get 64Meg of memory.
The applet thread priority sounds quite plausible.
 
A

Arne Vajhøj

Andrew said:
Had you any special reason to believe that GC algorithms
for applets might be different to an application?
> (I figure that a bit of 'speculation' is well on
> time for this thread - but just curious if you had
> any more specific basis for suggesting that.)

No. But there are a lot of GC algorithms/options.

Maybe someone at SUN was smart and finetuned the
plugin for small data and not these larger arrays.

But it is pure speculation.
To test that, you might sign the code and set
the security manager to 'null'. I was about to
try that the other night, but got distracted.

Not that I could see *anything* in the looped code
that should invoke a SecurityManager, but past
experience suggests that Sun checks some things I
would never have thought to.

The only place where they could check would be Math.random - and
I can not see any reason to do security checks in that.

But since I can not see any reason to why an applet should
run slower than an application, then ...
I am pretty certain that if only one applet is
running, that applet will get 64Meg of memory.
The applet thread priority sounds quite plausible.

Arne
 
R

Roedy Green

as possible the applet seems to perform quite a bit slower than the app.

There are two reasons:
1. with an Applet, RAM is full of browser code and tables.
2. with an Applet, you have no control over the heap size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top