Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

Блог пользователя SerVB

Автор SerVB, история, 8 лет назад, По-русски

Приветствую! Написав программу на Java и проверив ее в "запуске", обнаружил, что программа занимает в десять раз больше места, чем следует. Убрав весь код и запустив пустую программу, был неприятно удивлен. Она стала занимать чуть меньше 20 МБ и отработала за 61 мс...

Вопрос: это обычная ситуация или я что-то делаю не так? Ведь 20 МБ в спортивном программировании ох как не лишни. Да и откуда прибежали миллисекунды?

  • Проголосовать: нравится
  • +41
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

http://stackoverflow.com/questions/8361902/why-does-an-empty-java-program-consume-memory

<Место для вашей любимой шутки про прожорливость Джавы>

»
8 лет назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

IMPOSIBLE, THIS IS AMAZING, I EVER HAD SEEN!LOL!

»
8 лет назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

An ultimate proof that Java is slow.

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится +11 Проголосовать: не нравится

    Can you elaborate?

    • »
      »
      »
      8 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Java is often slower than C++ so I like making fun (example) of using Java in competitive programming, where the running time is (sometimes) crucial.

      • »
        »
        »
        »
        8 лет назад, # ^ |
          Проголосовать: нравится +17 Проголосовать: не нравится

        BTW, I have a problem where Java solution works for 0.8 sec, and C++ solution — 1.0 sec. Solutions are identical and use only arrays and primitive types. There are a lot of floating-point calculations in that problem.

      • »
        »
        »
        »
        8 лет назад, # ^ |
          Проголосовать: нравится +51 Проголосовать: не нравится

        So the only metric you think is important is runtime? Well, from what I know pure C is a bit faster than C++, why you are using C++ then?

        • »
          »
          »
          »
          »
          8 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Of course it isn't the only metric (why would you suggest so?). I also like built-in pairs and C++ provides that.

          I know that sometimes Java is a better choice, e.g. because it supports big integers. I can't say that Java is a worse language because it's better than C++ in some cases. What I always say is that it's slower (what hurts me often during the problem preparation) — and this is what I say in my trying-to-be-funny comments.

          Regarding your last question. Many contests support only C++ and Java, so I'm not going to use C. It's hard for me to find more reasons for not-using-C because I don't know C (and thus I can't compare it with C++).

          • »
            »
            »
            »
            »
            »
            8 лет назад, # ^ |
              Проголосовать: нравится +6 Проголосовать: не нравится

            Java is often slower than C++ so I like making fun (example) of using Java in competitive programming

            One can read this to suggest that if language is often slower than another that's the only thing that matters

            As for other points I do not see how built-in library matters nowadays in personal contests as you can have any prewritten code you want. And problems with problemsetting may be alleviated by basing your limits on unintended solutoions rather than intended ones, but that's topic for another discussion.

            Finally, barring edge cases you can usually submit your c source as c++ ;)

            • »
              »
              »
              »
              »
              »
              »
              8 лет назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              Ok, my words may indeed suggest that, my fault.

              I don't know if anyone agrees with me but it isn't that fun to maintain an own library (I'm not sure about this word — I mean a big set of prewritten codes). I understand that there are many cool problems requiring something complicated prewritten (ofc. you can also write it yourself during the contest) but I prefer hmm... simpler problems? Ones that you can code starting from an empty file. Similarly, I would want to read the input without anything pasted into the code. I see that I didn't show here any arguments — I simply don't have any (other than not being used to using much prewritten code). And of course it isn't anymore related to the Java vs. C++ discussion.

              Hah. Nice idea with submitting C as C++. Maybe I will even check out C one day. I still want to learn something about SSE first.

»
8 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

It cost 81ms on my laptop...

Java is a language running on virtual machine, so this behaviour is expected.