alibaba's blog

By alibaba, 10 years ago, In English

Today, when I try to solve this problem E. Pashmak and Graph, with exactly same code (except variable name) I got TLE when using Java 8 but AC when using Java 7, any ideas why?

Submission:

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

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

Disassemble can help you.

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

    The first idea I had when I saw this was: "yes, disassemble your computer" :D

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

      I do not understand — why the contestant who engaged in writing high-performance code should not be able to go down to low level its program/know implementation details of libraries or JIT? Particularly high ranked contestant.

      What you write in high-level languages does not mean that assebler you no longer need. Qualified performance engineers must have the notion about behavior of programs in all levels.

      Languages specifications or algorithms do not have the performance. Performance has only implementation.

      For Java you have open sources of whole enviroment, plenty of tools for analysis of low level code and benchmarking (for example, JMH), a lot of articles from Oracle's employee. Be cool, don't be lazy code monkeys!

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

        You're reading too deeply into it. I literally just said it was the first idea I got when I read your comment, nothing against assembly...

      • »
        »
        »
        »
        10 years ago, # ^ |
        Rev. 3   Vote: I like it 0 Vote: I do not like it

        Hmm, you should be cool first, no body is code monkeys here! Look into Assembly code is not a good idea, as it only show how this specific code is converted to assembly, but not why, If I want to avoid the same mistake, I need to know the right thing to read. Yes, there are a lot of articles, but I don't know which to start from, as this is not a normal behavior that you can search easily, that why we need a forum for thing like this! People are complaining about your advice as it is hard to read and understand, which show lack of commitment, and If it make you angry, be cool and be patient!

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

          What did you do for yourself in order to find the cause?

          • »
            »
            »
            »
            »
            »
            10 years ago, # ^ |
            Rev. 2   Vote: I like it 0 Vote: I do not like it

            You are making assumption my friend, you are trying to judge me, and I don't think I need to answer this question :)

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

The best/universal answer for java is

42

Creating new objects is the most vulnerable part of java. Maybe in java 8 they change some optimization.

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

There is a possibility that Arrays.sort implementation was changed or tweaked between Java 7 and Java 8. It is easy to check — just submit your solution with hand-written sorting routine.

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

Typical Java