> On Tuesday 22 April 2008 18:45:28 Richard Warburton wrote:
> > Could you please provide the source code for this performance comparison.
>
> Sure. The Java:
>
> public class test
> {
> int foo(int n)
> {
> return n - 1;
> }
>
> void bar()
> {
> }
>
> void baz()
> {
> }
>
> void run()
> {
> Exception e = new Exception("");
> try
>
> {
> for (int i=0; i<3; ++i)
> {
> if (foo(i) == 0) throw e;
> }
> }
> catch (Exception e2)
> {
> }
> bar();
> baz();
> }
>
> public static void main(String[] args)
> {
> for (int n=0; n<10; ++n)
> {
> long start = System.currentTimeMillis();
> for (int i=0; i<1000000; ++i)
> (new test()).run();
> System.out.println(System.currentTimeMillis() - start);
> }
> }
> }
Whilst I don't disagree with your overall comment that the JVM should
implement Tail Call elimination, I'm not entirely sure why people are
so interested in using exceptions to implement their specific control
flow semantics of choice anyway. For example replacing the contents
of the run method with;
for (int i=0; i<3; ++i)
{
if (foo(i) == 0) break;
}
bar();
baz();
Yielded performance improvements in the order of 100-200 over the
exceptional control flow based approach. I would expect that writing
a similar program in c# would produce similar results. Since it was
only running for < 20 milliseconds, its hard to gauge an actually
accurate time. I can see why an interprocedural control flow sequence
would map nicely onto exceptions - but if you are moving around within
a method then surely it would be preferrably to stick to goto based
control flow. This would assume that you are using bytecode as your
preferred method of output, rather than java source, but I think thats
a reasonable assumption anyway.
Richard Warburton
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---