Zzyzx's blog

By Zzyzx, 11 years ago, In English

Just recently I was trying to solve a problem but repeatedly encountered TLE verdict. This was while I was using Java 7.

Just thought I'd give it a shot and submitted the ditto same code but in Java 8. Works like a charm.

Java 7 submission Java 8 submission

And it's not some minor difference. There's a running time difference of > 2s, with Java 8 being the faster one.

I'm really curious as to why this happens. Yes, I know some kind of optimization is happening but what kind? A 2s difference is a LOT so it is non-trivial. Somebody explain?

  • Vote: I like it
  • +7
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Lol very interesting. Thanks for sharing this! No idea what's going on :o

»
11 years ago, # |
  Vote: I like it +6 Vote: I do not like it
»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

i got the result conversely. in my submission java 6 is the fastest.

java 6 java 7 java 8

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    You can't compare performance with such trivial code. If you submit it multiple times, you will probably see execution time fluctuate wildly.

    You should solve some computationally expensive problem and then test the performance.

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I might be wrong, but it might be that JAVA 8 always uses "server" VM when Java 7 defaults to "client".