Slashdot Mirror


See the PyPy JIT In Action

derGoldstein writes "Project PyPy is an alternative implementation of Python, with the main advantage being a Just In Time (JIT) compiler which speeds up your code considerably. They've announced the first public release of jitviewer, which is a visualization tool that helps you understand how your code is being compiled by PyPy's JIT, all the way down to assembly. If you just want to see how it looks and play with it, they've set up an online demo — just select a file, and click 'Show Assembler.'"

109 comments

  1. And their gone by Anonymous Coward · · Score: 0

    Slashdot DDOS machine in full effect

    1. Re:And their gone by Anonymous Coward · · Score: 0

      They should have built their site on Java.

    2. Re:And their gone by jonahbron · · Score: 1

      I think you mean "And they're gone"

      Unless they actually a possess a "gone"...

      ...whatever that is...

    3. Re:And their gone by kiddygrinder · · Score: 1

      plenty of high traffic sites use python

      --
      This is a joke. I am joking. Joke joke joke.
    4. Re:And their gone by Anonymous Coward · · Score: 0

      Actually, GP was talking about a gone Slashdot DDOS machine, and it is believed to be a machine that scans the front page of Slashdot and randomly turns off servers the articles link to.

    5. Re:And their gone by sycodon · · Score: 1

      When are they going to start calling these thing YAPython and YAPerl?

      --
      When Fascism comes to America, it will call itself Anti-Fascism, and tell you to give up your guns.
    6. Re:And their gone by GooberToo · · Score: 0

      The fact this post isn't at -1 after a day wonderfully proves just how completely broken the moderation system is on slashdot. And by moderation system, I mean those who use it.

  2. Go Pypy! by Anonymous Coward · · Score: 4, Informative

    I love python, and pypy makes dream about the day python could be used for anything, making java irrelevant.
    The language is readable, flexible, succinct, expressive and beautiful.
    Programming in python is more a joy than a core, but it has always suffered from a wide performance gap in cpu intensive tasks compared to traditional static languages.
    Hopefully, this is all about to change with projects like this.
    It's worth noting that Pypy is more than just an alternative python implementation. It is a framework for implementing jitted compiled dynamic languages.
    There are currently several works in progress with implementations of javascript, scheme, logo, php and other languages with pypy.

    1. Re:Go Pypy! by AwesomeMcgee · · Score: 1

      Good to know, I've toyed with the idea of trying to create a javascript jit, anyone who understands crockfordscript (which these days is practically everybody, making it all the more valueable) recognizes performance is the only thing missing from what could be one hell of a good language..

    2. Re:Go Pypy! by TheStonepedo · · Score: 1

      Thanks anon!
      Somebody should mod this coward up.

      --
      I'll be your candy shop of infinite deliciousity if you'll be my discotheque of endless rump-shaking.
    3. Re:Go Pypy! by icebraining · · Score: 1

      Uh, both Google's V8 and Mozilla's Tracemonkey are JIT engines. There's nothing wrong about creating your own, but if it's a question of speed and not about learning, sticking with V8 is probably a better option.

    4. Re:Go Pypy! by H0p313ss · · Score: 2, Insightful

      The language is readable, flexible, succinct, expressive and beautiful.

      I hear it cures cancer too. Oh wait, that's Ruby. (Actually, I love Python, but I'm allergic to fanboism...)

      --
      XML is a known as a key material required to create SMD: Software of Mass Destruction
    5. Re:Go Pypy! by Anonymous Coward · · Score: 3, Insightful

      Python is not going to make Java irrelevant. Sorry. I know it hurts to be told that your religion will never become universal, but that's reality for you.

      Certainly one reason for choosing Java over Python today is performance. Python is relatively slow, and sometimes throwing more hardware at the problem is not an option, and rewriting stuff in C (like Python fanboys always suggest) is not actually that easy (and brings with it all the problems of writing anything in C -- there's a reason we want to use Python or Java in the first place, right?)

      But performance is only one of the reasons. The kinds of organization that choose Java appreciate a number of things it provides that Python, by design, will never provide. Such as static guarantees of any sort, or the ability to enforce the separation of public/private APIs rather than relying on "convention". (No, Python fanboys, reflection in Java does not subvert all access checks.)

      There are entire classes of Python bug that are simply impossible in Java. Passing the wrong object type as a parameter. Accessing a non-existent variable because you made a typo in the name, or because you forgot that Python does not have lexical scoping. And so on. If your developers are not all the most brilliant hackers in the world -- as is the case in most Java shops -- these things are problems with Python. (No, fanboys, unit testing is not a substitute for type-checking and variable declarations. Hint: if your developers are not wonderful developers, they probably aren't wonderful test writers either.)

      Python is great for small-scale projects or for enthusiasts, and it can be used for large-scale projects where you have a small team of highly-skilled developers, but those are not the markets Java is used in, and performance is not the primary reason why Java is used in those markets. After all, if all they cared about was performance, they'd use C++.

    6. Re:Go Pypy! by buchner.johannes · · Score: 2

      The whole Java *or* Python discussion is irrelevant. You can use Jython, and take advantage of all the Python and Java libraries.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    7. Re:Go Pypy! by OeLeWaPpErKe · · Score: 2, Insightful

      You're argument only makes sense if you accept that the python language design requires dynamic typing. And this may (may) be true for the really advanced and esoteric uses of python, but anyone who's ever built a tiny compiler knows that 95% of python can easily be implemented statically typed. It would be a great exercise to try to fully inline the entire python runtime library to cover the remaining 5%.

      Personally I'm convinced that a statically typed python supporting 90% of common use cases, and the IDE and tools that are possible to build using such a language would blow the regular python out of the water. Python's "dynamic" typing is in reality no more powerful than inference + splitting (ie. if you do 'x = 5; print x + 1; x = "boe"; print x + "1";' translate to 'x = 5; print x + 1; y = "boe"; print y + "1"', and split the variable name when re-typing occurs). And is there anyone here claiming that java's ctrl+space wouldn't be a great help in writing library intensive python code, never mind all other refactorings ?

      I may understand in practice why people use dynamically typed languages, but theoretically there is no good reason for using dynamic typing at all. Furthermore python's "garbage collector" is so extremely basic it could simply be moved to compile time (I mean that there is no theoretical problem predicting all allocations of a python program at compile time, so (if you had a year to get this right) you could make python object allocation compile to a nop.

    8. Re:Go Pypy! by AtlantaSteve · · Score: 1

      The whole Java *or* Python discussion is irrelevant. You can use Jython, and take advantage of all the Python and Java libraries.

      Did you not read a word that this guy wrote, or did you simply not understand any of his points?

      The weaknesses that he pointed out did not deal with Python "lacking access to Java libraries". The weaknesses that were pointed out included Python's lack of compile-time type-checking, lack of real publication and enforcement of API contracts, and lack of lexical scope.

      Jython addresses none of that. It does not magically transform Python from a hacky Perl-successor into a language broadly suitable for large scale enterprise development. It's just a library that lets you run your same old hacky scripts on a JVM.

    9. Re:Go Pypy! by Anonymous Coward · · Score: 0

      I'm allergic to insane formatting requirements.

    10. Re:Go Pypy! by Anonymous Coward · · Score: 0

      Hey, Ruby is also a beautiful language. The fact that I like Python doesn't mean I don't like other languages.
      I'm simply happy to see python implementation making strides, becoming faster and better for all purposes.

    11. Re:Go Pypy! by Anonymous Coward · · Score: 0

      theoretically there is no good reason for using dynamic typing at all.

      How about "an object is an object"? An identifier is an identifier. In a pure OO language like Smalltalk, there is no reason to limit an identifier to a particular data type - and actually no reason to make the data type static.

    12. Re:Go Pypy! by Tumbleweed · · Score: 2

      I hear it cures cancer too. Oh wait, that's Ruby. (Actually, I love Python, but I'm allergic to fanboism...)

      While it's true that Ruby cures (certain types of) cancer, it also has the unfortunate side effect of causing autism. Don't believe me? Try reading non-Ruby code written by Ruby fans.

    13. Re:Go Pypy! by Anonymous Coward · · Score: 0

      Well, all the major javascript engines use JIT in one form or another nowadays

    14. Re:Go Pypy! by chromatic · · Score: 1

      [T]here is no theoretical problem predicting all allocations of a python program at compile time...

      ... until you do IO.

    15. Re:Go Pypy! by OeLeWaPpErKe · · Score: 1

      Everything is an object is not a property of dynamically typed languages, nor is it a property of static languages. It can be part of language design, or it can not be. It won't force a language to be either static or dynamically typed. Imho, usually laziness of language designers is what makes languages dynamically typed. Some at least have the decency to limit that dynamic typing to the implementation,and not build it into the design.

      Personally I find the one language that actually does the "everything is an object" thing correctly is C++. Python and Ruby and the like cheat : in java parlance they only have Integers and Floats and lack int and float types (and they lack &int and &float, but so does java. Actually python only really has a BigInteger). They only have pointer types and they implement hugely confusing calling conventions (at least from the viewpoint of someone who actually knows how a computer works) (and with C++0x you could say that there is a new gaping hole in most languages : move semantics versus copy semantics)

      C++ by contrast has all the options : int, int*, int&, float, float*, float&, and you can stick all of them in a collection without issues. Well, except if you're shooting yourself in the foot and there is no way for the compiler to fix it.

    16. Re:Go Pypy! by OeLeWaPpErKe · · Score: 1

      Yes, but even then you can still group them into large chunks, instead of small allocations.

    17. Re:Go Pypy! by Anonymous Coward · · Score: 0

      In C++, nothing is an Object - because there is no Object.
      There's no common base class that everything inherits from that describes the fundamental behaviour of an object.

      I think you need to spend some time actually fully learning a language like Smalltalk - where the language doesn't get in the way of the pure Object Oriented principles.

    18. Re:Go Pypy! by smallfries · · Score: 1

      So you are claiming that duck typing is not used in practice other than in esoteric projects. That is a little bit naive, consider why would something so complex be left in the language design if it was not necessary? The entire language relies on duck typing being there to make some other design decisions easier to make, for example all containers are polymorphic collections rather than the monomorphic collections in almost every other language. Your fragment of code is a single instance where forward interference would work with name splitting on use (aka ssa form). But it is not powerful enough to handle the whole language. Consider: x = Foo() if(...) else : Bar(). What type is x after the statement? In the presence of conditional branches you need some kind of phi nodes to merge the symbols. It's the same problem that ssa suffers from in maintaing the precision of modelling which values exit a computation.

      That's one of the easy ones, how about d[key1] = Foo() ... d[key2] = Bar() .... Lots of different object type under different keys. Somewhere later your analyser hits the value d[some expression]. What type comes back out?

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    19. Re:Go Pypy! by Anonymous Coward · · Score: 0

      Boo is designed to be like Python, but with static typing. It's not easy for alternative languages to gain traction, though.

    20. Re:Go Pypy! by ThePhilips · · Score: 2

      [...] and rewriting stuff in C (like Python fanboys always suggest) is not actually that easy (and brings with it all the problems of writing anything in C -- there's a reason we want to use Python or Java in the first place, right?)

      Actually, dismissing writing parts in C is not so simple. The only problem I'm aware of is the portability. And even that is handled by package/module management automatically.

      Otherwise, most problem-free C programming I ever done (as C stuff goes) was Perl XS (*). Because you can leave to Perl all the mundane tasks and implement in C only the most performance-critical parts, which often have well defined input and well defined output. Even memory allocation stops being a problem: the objects one allocates in Perl XS come from Perl's GCed pool and managed automatically.

      But of course, I'm not disagreeing with you in general: in Python, there are way too many cases where performance is simply unacceptable and everytime dropping into C would be a nightmare for a project of any scale.

      (*) Learning Perl XS was a bitch, but I heard Python has much much more straight forward and well documented C interface.

      The kinds of organization that choose Java appreciate a number of things it provides that Python, by design, will never provide.

      The "number of things" are actually much more trivial this days and is not related to technical side of things: it is the pool of cheap workforce (out-sourceable too) which keeps most organizations addicted to Java.

      and performance is not the primary reason why Java is used in those markets.

      It is not the primary reason, but performance played its role in Java adoption. Recall why its predecessor Smalltalk never caught up: because it was dog slow and resource hungry.

      --
      All hope abandon ye who enter here.
    21. Re:Go Pypy! by KDR_11k · · Score: 1

      Is PyPy very different from Psyco? I've been using the latter for scripts that needed speedups.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    22. Re:Go Pypy! by Anonymous Coward · · Score: 0

      You can use a structural type system of course which solves this problem.

    23. Re:Go Pypy! by KDR_11k · · Score: 1

      The reason for static typing is not implementation difficulties but bug checking. When I need an int variable I can declare it as such and make sure I never accidentally stick anything else into that variable. With dynamic typing a function can return values of different types or maybe a programming mistake makes the variable contain "3" instead of 3 and the error only pops up when something assumes you give it an int and it finds something else. In something like Lua you can have functions that return a value or nil but nil is usually in case of an error. If you don't diligently stick error handling behind every such function call you'll end up with an error many lines down and the fun trying to debug what caused the nil and where it is (if you got a few stacked tables and one of the tables in the pile is a nil it won't even tell you how deep down the nil was).

      Static typing prevents user errors. Being able to detect errors where they happen greatly improves debugging and testing, helping massively with making sure the shipped product has fewer errors. The goal of modern high-level languages is to make it easier to keep the error count down and thus development costs down.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    24. Re:Go Pypy! by Ragzouken · · Score: 1

      From what I understand, Psyco is the father of PyPy. Psyco is a finished project, and the things learnt from it are being developed and refined in the PyPy project.

    25. Re:Go Pypy! by Anonymous Coward · · Score: 0

      urr urr urr blah blah the So Called Enterprise blah blah

      loosen yer khackies corporate boy I think the bloat of your self pride is cutting off circulation to your head

    26. Re:Go Pypy! by Requiem18th · · Score: 2

      Javascript is not a nice language, it's the unholy chimera of Self and Java.

      Sure it's better than how most people describe it, but there are far better languages out there.

      --
      But... the future refused to change.
    27. Re:Go Pypy! by sgt+scrub · · Score: 1

      Your just scared because it allows one to quickly migrate U235.XML to U238.XML.

      --
      Having to work for a living is the root of all evil.
    28. Re:Go Pypy! by shutdown+-p+now · · Score: 1

      Are you a Java coder? There is no need to have a common base class named "object" to define the fundamental behavior of objects.

    29. Re:Go Pypy! by thePuck77 · · Score: 1

      Alright, give me an alternative that does the same thing. I agree...JS is a dirty, problem-inducing (rather than problem solving) language. I just don't know what else I can use to move things around and cause the useful JS effects without a refresh without JS.

      --
      "We live as though the world were as it should be, to show it what it can be." - Joss Whedon via Angel
    30. Re:Go Pypy! by thePuck77 · · Score: 1

      Go comeback. Really. The height of wit.

      Except, you know...all of his points are valid and until we address them Python is the new Perl. Maybe you aren't old enough, Mr. Coward, but I remember when Perl was the new toy and people thought it was the best thing since sliced bread (hell, it would slice the bread for you).

      --
      "We live as though the world were as it should be, to show it what it can be." - Joss Whedon via Angel
    31. Re:Go Pypy! by thePuck77 · · Score: 1

      Ding ding ding! We have a winner!

      --
      "We live as though the world were as it should be, to show it what it can be." - Joss Whedon via Angel
    32. Re:Go Pypy! by rwa2 · · Score: 1

      I used psyco for my thesis back in 2007. It improved my SimPy runtimes by a factor of 100, merely with a simple "import psyco" in the beginning of the project!

      Unfortunately psyco only works on 32-bit architectures, and after I got my degree I finally upgraded to a 64-bit system and sat on my work waiting for something to happen. Now I guess I finally need to pull it out again and see what's up.

    33. Re:Go Pypy! by Anonymous Coward · · Score: 0

      The reason for static typing is not implementation difficulties but bug checking. When I need an int variable I can declare it as such and make sure I never accidentally stick anything else into that variable.

      The point of dynamic typing is that it doesn't matter if you stick anything else into that variable. It's not an error.

      Your problem is that you're stuck in procedural way of thinking about variables.

    34. Re:Go Pypy! by Requiem18th · · Score: 1

      Self, Io-language, Smalltalk, Ruby and of course Python or even Lisp, but also Java, C# or Vala if you want static typing.

      You mean something supported on todays browsers? Yes, Javascript. But as long as you are reinventing the browser you can always pick a better scripting language.

      --
      But... the future refused to change.
    35. Re:Go Pypy! by thePuck77 · · Score: 1

      Well, if I have the luxury of reinventing the browser and choosing a new standard, I would vote for Smalltalk (I would say Lisp, but I foresee forcing too many square pegs in round holes to go there). But right now we are stuck with JS or running things through the Java JIT.

      --
      "We live as though the world were as it should be, to show it what it can be." - Joss Whedon via Angel
    36. Re:Go Pypy! by Anonymous Coward · · Score: 0

      First, Go allows exactly this. There are multiple ways of doing it :

      first, the "dynamic" way : void * comes out and you use RTTI (this is what python does)

      second way, you can best imagine how this works if you think of it as a huge inheritance diagram. You create an "Object" class, which has every possible routine, variable and so one that is used anywhere in your program. Then everything inherits from Object, and so you can call any operation on any object, it's just that most of these routines point to "throw AttributeError". Then optimize this.

      third way, you detemine the set of all possibilities of what is inside this collection, then create an implicit case class of all the possibilities you could get and use that type.

      fourth way, you simply disallow this. If the compiler can't determine how to change dict into dict, you simply err out.

    37. Re:Go Pypy! by smallfries · · Score: 1

      You've missed the point: yes it is easy to do this dynamically at the cost of performance. The comment was in response to the claim that doing it statically is easy. It's not easy to analyse this statically, but when it can be done the performance increase is large. One optimisation that it allows straight away is unboxing which can easily increase the performance of numerical code by an order of magnitude.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  3. And by see you mean by Anonymous Coward · · Score: 3, Funny

    the connection has timed out

    Python, the new Java

    1. Re:And by see you mean by rafe.kettler · · Score: 0

      Slashdot has taken down plenty of websites written in a wide variety of languages.

    2. Re:And by see you mean by Anonymous Coward · · Score: 0

      There needs to be a +1 Oh Yeah for mod points. WE can all be proud of /. a site.

  4. Re:My first time at that by Anonymous Coward · · Score: 0

    Dude, you really need to remember to log out when you have kids in the house.

  5. Woo hoo! by 93+Escort+Wagon · · Score: 3, Informative

    I'm glad to see it scales well!

    --
    #DeleteChrome
  6. It's Python. It's Java. It's Jython. by tepples · · Score: 0

    Python, the new Java

    That's Jython, not PyPy.

    1. Re:It's Python. It's Java. It's Jython. by Anonymous Coward · · Score: 0, Informative

      umm?!? whoosh?

  7. LLVM? by jcr · · Score: 0

    Someone remind me... Isn't PyPy the implementation that's based on LLVM?

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
    1. Re:LLVM? by Courageous · · Score: 0

      Here's your reminder:

      http://tinyurl.com/42jo3qv

    2. Re:LLVM? by rg3 · · Score: 2

      No, that was Unladen Swallow.

    3. Re:LLVM? by MtHuurne · · Score: 1

      No, that is Unladen Swallow.

    4. Re:LLVM? by Anonymous Coward · · Score: 0

      Link is just: http://www.lmgtfy.com/?q=pypy+llvm
      So not Goatse.

    5. Re:LLVM? by Anonymous Coward · · Score: 0

      Nah, LLVM (with all its bugs) fucked up the whole Unladan Swallow project, which was sponsored by Google, and speculated to be used as the native Android language.

    6. Re:LLVM? by Millennium · · Score: 1

      No. IIRC it can compile to LLVM (it's actually got a bunch of backends), but it isn't actually based on LLVM itself.

  8. Re:My first time at that by Anonymous Coward · · Score: 0

    Now, I understand why python executes so fast. Good tool. Is this why the link to "online demo" is broken?

  9. Not a big fan of Python, but... by Anonymous Coward · · Score: 0

    Not a big fan of Python, but at some point I decided that an important check-off for any language is whether or not it can self-compile (or self interpret). PyPy gives it that checkoff and hat's off for having a JIT.

    Compare and contrast with Larry Wall's admission that Perl isn't for everything, noting that Perl isn't written in Perl. In retrospect, that should have been a red flag. C is written in C, Lisp is written in Lisp to the point where it makes your mind warp. Not sure about Java; but it seems likely that somebody has done it.

    1. Re:Not a big fan of Python, but... by icebraining · · Score: 1

      I think Rakudo Star is written in Perl 6 (or a subset of it). At least that was my understanding after listening to one of its devs talk about its history.

    2. Re:Not a big fan of Python, but... by Mitchell314 · · Score: 1

      I think javac is a java program.

      --
      I read TFA and all I got was this lousy cookie
    3. Re:Not a big fan of Python, but... by Anonymous Coward · · Score: 1

      Javac is in java, yes, but the JVM is written in C++.

      IBM's Jikes RVM is a JVM written in Java. They use it as a research platform (the R stands for "research").

  10. Re:Another example of Open Source showing immaturi by thetoadwarrior · · Score: 1

    So what is named after a penis?

  11. Re:Another example of Open Source showing immaturi by Anonymous Coward · · Score: 1

    I think he is pronouncing PyPy as "pee-pee" instead of "pie-pie".

  12. Re:The difference between Python and Ruby devs. by Anonymous Coward · · Score: 2, Interesting

    I'm a python fan, but I think you are being a little bit unfair with the ruby community.
    Python simply has more people working on making it fast (the pypy project started 8 years ago, and only recently it started to deliver on its promises).
    By the way, pypy is a framework for creating jitted dynamic languages (it's written in python, but can be used to implement any other language).
    So chances are that soon, someone will write a Ruby implementation with pypy, and this ruby vm will enjoy all the performance of the python one, because it will have an automatically created just-in-time compiler.

  13. Re:Another example of Open Source showing immaturi by whoop · · Score: 1

    Good idea. I say we shall henceforth pronouce this language as Pee-thon.

  14. Quora by Anonymous Coward · · Score: 2, Interesting

    quora.com is now running on PyPy.

    http://www.quora.com/Alex-Gaynor/Quora-product/Quora-is-now-running-on-PyPy

  15. Faster than C? by lee1 · · Score: 3, Informative

    Not just faster than CPython, but faster than C for some common tasks. Pretty amazing.

    However, this project is not yet very useful to the people who might be most interested in a really fast python, as it does not work with numpy. But when they get that to work, wow.

    1. Re:Faster than C? by Anonymous Coward · · Score: 0

      This was for one example, Python has, and will remain eternally slower than C.

      I'd love to see how PyPy stacks up to LuaJIT.

    2. Re:Faster than C? by whiteboy86 · · Score: 1

      Dream on, its like those 'over unity' energy source claims.

    3. Re:Faster than C? by Anonymous Coward · · Score: 0

      it's nice. but do we know it's not just obvious optimisation?
      in his test the python and c code don't return values, nor print values (ie. no i/o)
      if i made a jit compiler and encountered a loop that changed nothing external to it, and resulted in no i/o, i'd call roll it up as a nop and remove it

      or a more obvious optimisation would be to allocate a block of memory
      in the loop let the string be allocated to the start of the block
      knowing the data is local scope only, no point expanding memory or moving the point in the memory block
      so simply keep writing the result to the same spot over and over again

    4. Re:Faster than C? by Anonymous Coward · · Score: 0

      ... comparison is missing how it was timed:

      It took 0.85 seconds to execute under PyPy, and 1.63 seconds with the compiled binary.

      this could easily mean the c binary was timed when the person pressed enter to execute the c binary, to when it returned back to the prompt (ie. timex)
      whereas pypy could be using timing from the virtual machine so starts at the beginning of actual script execution after having compiled it 'just in time', and stops when the script finishes, but not before the vm kicks in cleaning up all the crap the script left behind

      which from one standpoint is fair enough as you're really comparing the "compiled" code execution
      from another standpoint though it's just plain bollocks as it doesn't account for the virtual machine

      my comments are speculation due to lack of detail from the source material

      overall i'm not trying to detract from python
      for an interpretted language it has the potential to run damn fast
      but i wouldn't be using it for any big iron or critical systems anytime soon

    5. Re:Faster than C? by nzac · · Score: 1

      Did you read the comments?
      That's not a common task if he created a file with a meaningful output it would be a good benchmark.

      This looks to either be a stumbled on case or something contrived. He used -O4 for crying out loud (it's treated as -O3) there could be a bug from excessive optimization and the main function sprintf cannot be optimized as its a pre complied library (i could be wrong here).

      The result is best summed up by the comment:

      PyPy does nothing 1.9 times faster than C.

    6. Re:Faster than C? by Anonymous Coward · · Score: 0

      If you're comparing speed against C code that spends significant time doing mallocs then you're not comparing against high-performance C code.

    7. Re:Faster than C? by lee1 · · Score: 1

      As he says himself, "the sprintf function lives in libc and so cannot be specializing over the constant string, which has to be parsed every time it's executed. In the case of PyPy, we specialize the assembler if we detect the left hand string of the modulo operator to be constant."

    8. Re:Faster than C? by complex_pi · · Score: 1

      Also, it needs to be able to call C and Fortran libraries to be really useful in NumPy. Because no one is going to rewrite all of those numerical libraries.

    9. Re:Faster than C? by nzac · · Score: 1

      So what they are really saying is pypy is faster than a function in glibc for a task that glibc would never be used for (i would think you chose a modern library if you wanted to do this in some real code).
      This is benchmarking not against C but a bloated and not particularly optimized library.

    10. Re:Faster than C? by m50d · · Score: 1

      Huh? How else would you do the given task in C? And glibc is the standard C library on most current linucies. It's absolutely a relevant comparison.

      --
      I am trolling
    11. Re:Faster than C? by nzac · · Score: 1

      If you were going to do this as a one off sure you would use libc if you are going to do the same thing 10000 times in a row as you entire program and care about performance you would look for something better (this would likely be libboost in C++).

      For anything to do with strings python is far more expressive than c and this case could be the more elegant and robust solution (except for memory usage). For this example i guess you 'parse' (not sure if that's the correct term in C) the text before the looping and store the result in a structure and then while looping though pass the structure as an argument this requires new libraries or you to write your own. Unless you allow on the fly editing in python I think its still equivalent function.

      http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
      http://bstring.sourceforge.net/features.html
      The first shows that the sprintf is bloated for the benchmarks purpose.
      The second link is of library i found from google that says it has 3980% increased performance for string concatenation (other improvements are more modest) over libc if this figure is correct then a pypy has not beaten c and that sprintf is pretty bloated. I don't not check it had the equivalent functions for this problem. Its difficult to argue this as coming up with an alternative way to do nothing in C has arbitrary rules.

    12. Re:Faster than C? by m50d · · Score: 1
      We're talking C, not C++, so boost is irrelevant. Sure sprintf is big and flexible, but so is python's % operator; the comparison is a fair one, standard language feature to standard language feature. You may well have a faster string library, but using nonstandard libraries has its own problems - you now have two different ways to format your strings, and if you try and do the same thing with some other part of your program (say introduce a nonstandard faster networking library) then whoops, your two nonstandard libraries don't work with each other and you're stuffed.

      Of course it's a small, arbitrary comparison, but it's a fair one, with the same rules for both sides - we're talking about the natural, obvious, standard way of writing the same operation in each language. If you want to make it a C victory on the same terms I'd be interested to see whether ICC's whole-program optimization is able to push the constant string down through the standard library.

      --
      I am trolling
    13. Re:Faster than C? by nzac · · Score: 1

      We are talking about pypy being better than native programs so if C++ benchmarks are also valid. If this is just a contest to convert an integer to a string and write it to arbitrary memory as fast as you can and not factoring in pythons order of magnitude(s) greater expressiveness and readability. You are taking a standard data type and returning an array of standard data there no issues with other libraries. Using a copy and pasted integer to string function (itoa(...)) that has some checking of valid inputs this will do the job in less than percent of the time under -O3 (no optimization is barely faster so an optimized sprintf could be faster). My CPU is not as good as his.
      int main() {
              int i = 0;
              int ilt=0;
              int val=0;
              char x[44];
              char buffer[15];
              for (i = 0; i less than 10000000; i++) {
                  ilt=0;val=0;
                  itoa (i,buffer,10);
                  while (x[ilt]){
              x[ilt]=buffer[ilt];
              ilt++;
                  }
                  x[ilt]=" ";
                  val=ilt;
                  ilt=0;
                  while (x[ilt]){
              x[ilt+val]=buffer[ilt];
              ilt++;
                  }
                  x[ilt+val]="\0";
              }
      }
      I think that still pretty impressive of pypy but there are sill corners that could be cut for the c code. For easy native speed string manipulation C++ is far superior to C for writing and reading of code operator overloading, classes and pretty much half of the extra of it this allow people far more skilled than myself to optimize the program.

      Of course it's a small, arbitrary comparison, but it's a fair one, with the same rules for both sides - we're talking about the natural, obvious, standard way of writing the same operation in each language.

      Not really the C code from his example was just as fast under O1 yet he cranked it up to O3/4 and says it's a fully optermised benchmark. The only reason to code this in C is if you want peak performance if you want to use similar language to python you would use C++ with the string libraries. C's lack of objects makes dealing with strings a verbose task that there is no good reason to undertake it for general use and therefore there are no better solutions.

  16. PyPy solves a very hard problem, but is still slow by Animats · · Score: 4, Informative

    It's an impressive effort that they were able to get this to work at all. Python is really tough to optimize. All bindings are changeable at any time, even from another thread. (The latter is silly, but since it doesn't cost anything to do that in CPython, which is an inefficient naive interpreter that can only run one thread at a time and spends much of its time doing dictionary lookups. Von Rossum defines the language by what CPython can do. There's a huge speed penalty for allowing such extreme dynamism, about 60x over C/C++. The Google team tried to fix that with Unladen Swallow, but gave up when their JIT system was barely faster than CPython.)

    PyPy's most effective optimization to date is that it figures out when numbers don't have to be boxed. This allows generating numeric machine code, rather than grinding through the object machinery for every number. They have to be prepared to discard code when something binding gets changed. This requires a very complex system, involving two interpreters (regular and backup) as well as the JIT compiler.

    The PyPy crowd is at last starting on the tougher optimizations, like hoisting some operations out of loops. (FORTRAN compilers were doing this in the 1960s.) That's real progress, but it's very hard to do in such a dynamic language.

    Many of the optimizations involve generating run-time code that checks to see if the normal case is occurring, and that no other code has patched the code or changed the data from the outside in a way that invalidates the fast path. Then there's code to unwind what the fast path was doing, and interpret or recompile. Most such code is never executed.

  17. "if all they cared about was performance, by Anonymous Coward · · Score: 0

    they'd use C++.", as you said? Funny - isn't Python written in C++ in its libraries of functions?? That said, it should have the same performance when you call its libs functions then! Your "argument" there, falls right apart.

    1. Re:"if all they cared about was performance, by Anonymous Coward · · Score: 0

      they'd use C++.", as you said? Funny - isn't Python written in C++ in its libraries of functions?? That said, it should have the same performance when you call its libs functions then! Your "argument" there, falls right apart.

      ...because there's absolutely no overhead from calling these functions from a dynamically typed language right? The cache-misses and pipeline stalls that will result from this are not trivial, and will have performance issues that will be orders of magnitude larger then what you see in a C++ (assuming a decent compiler that is).

  18. LuaJIT by Anonymous Coward · · Score: 0

    Let's see some comparisons to real JIT compilation, LuaJIT.

    1. Re:LuaJIT by Anonymous Coward · · Score: 0

      Luajit is absolutely great, and Mike Pall (its creator) is a bad ass programmer.
      But Lua is simpler language, much more than python or javascript.
      It has a small core, only one container data type and no batteries included. Hence it's easier to optimize.
      Even Mike Pall recognized that doing the same thing for python would take years, not months as luajit. And this approach wouldn't have all the other advantages of the pypy project, which is a framework for writing dynamic language virtual machines with built in just-in-time compilers.

  19. Re:Another example of Open Source showing immaturi by JonySuede · · Score: 2

    sorry for the accidental drunken redundant moderation. I deeply apologize.

    --
    Jehovah be praised, Oracle was not selected
  20. Re:PyPy solves a very hard problem, but is still s by jgrahn · · Score: 1

    There's a huge speed penalty for allowing such extreme dynamism, about 60x over C/C++.

    That number is surely made up; perhaps it applies to some specific set of benchmarks? In reality the factor is going to vary widely depending on the problem. And oh, you can't lump C and C++ together and call them C/C++.

  21. UR argument falls apart fast (especially API) by Anonymous Coward · · Score: 0

    1.) Those pipeline stalls would only result IFYou sent bad data to them (That's the fault of the coder or DBA for example, since you mentioned dynamically typed in your statement).

    2.) Overheads from function calls are not that big. They get marshalled in process and lib loads are not "all or nothing".

    (I.E./E.G. -> You only load the portion/function you need into the calling process, NOT the entire library itself!)

    ---

    Thus, Your "argument's" are falling apart fast, and on 2 grounds:

    A.) Most programmers or DBA's aren't that stupid about data sanity, not even rookies as far as dynamically typed languages.

    B.) Secondly, you're making it sound as if calling out libs/dlls is some "huge overhead" well if so, how come Operating System API's work so well and fast then??

  22. Re:PyPy solves a very hard problem, but is still s by smallfries · · Score: 1

    It matches what I've seen. I've written compilers, static analysers and visualisation code in Python. In most cases there is about a 100x difference in speed between the Python code and C code to implement the same algorithm. Python is still useful for prototyping in as most of that code could be written 5x to 10x more quickly than the C code.

    --
    Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  23. Re:PyPy solves a very hard problem, but is still s by smallfries · · Score: 1

    I noticed that their progress seemed to have stopped, is there any official announcement?

    The Google team tried to fix that with Unladen Swallow, but gave up when their JIT system was barely faster than CPython.)

    --
    Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  24. And now for ruby please by swarsron · · Score: 1

    And now for ruby please. I love ruby, but the performance issues drive me crazy sometimes.

    1. Re:And now for ruby please by Anonymous Coward · · Score: 0

      Write a Ruby interpreter in RPython. You get the JIT for free.

    2. Re:And now for ruby please by Moldiver · · Score: 1

      Get a Mac and have a look at MacRuby. Near Obj-C Performance and JIT/AOT through LLVM.

  25. Re:PyPy solves a very hard problem, but is still s by Animats · · Score: 1

    I noticed that their (Unladen Swallow) progress seemed to have stopped, is there any official announcement?

    Unladen Swallow is an ex-parrot.. "Jeffrey and I have been pulled on to other projects of higher importance to Google.", writes the former project lead.

  26. Re:PyPy solves a very hard problem, but is still s by Anonymous Coward · · Score: 0

    In my experience, C tends to compile to about 1-6 lines of asm instructions, virtually all of which are necessary to perform the required task.

    If you get 60 times faster than that without changing your algorithms, even with hand-coded assembly and intimate knowledge of the hardware, you're probably bypassing the entire CPU and running on moonjuice.

  27. Horrible Name by Digital+Mage · · Score: 1

    I'm sorry...I don't want to see how it looks or play with your PyPy. I will most definitely NOT click on your online demo to show your "Assembler".

  28. Re:PyPy solves a very hard problem, but is still s by dkf · · Score: 1

    Higher-level languages produce more asm per line but express more operations per line too. Easier to (validly) compare at the level of functions or whole programs.

    If you get 60 times faster than that without changing your algorithms, even with hand-coded assembly and intimate knowledge of the hardware, you're probably bypassing the entire CPU and running on moonjuice.

    Or spotting that something can be evaluated to a constant during compilation. That's a huge win when you can do it.

    Of course, the other thing is that it is ever-so possible to write poor C code that can be out-performed by code generated from another language. A classic example of this is in string handling, where the C standard library routines can easily be used to create code with an awful performance, e.g., by repeatedly calling strcat() on the same long string, and any language with a string data structure more suited to repeated appending will outperform that. OTOH, a truly good C programmer will be using the right data structures and algorithms in the first place, making this a bit of a moot point.

    --
    "Little does he know, but there is no 'I' in 'Idiot'!"
  29. Re:PyPy solves a very hard problem, but is still s by smallfries · · Score: 1

    Actually he just completely misread my post. The 60x increase was Python -> C, not from C -> assembly.

    --
    Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  30. Re:PyPy solves a very hard problem, but is still s by Anonymous Coward · · Score: 0

    The same type of moonjuice that would make an AC mistake the word 'penalty' for 'increase'?

  31. Re:PyPy solves a very hard problem, but is still s by White+Flame · · Score: 1

    Lisp yawns at how easily impressed you are.

  32. I don't see this working by Lobais · · Score: 1

    Seams boxing isn't too much of an issue for vanilla python when summing 1000,000 integers.

    $ pypy -m timeit "sum(range(1000000))"
    10 loops, best of 3: 55.2 msec per loop
    $ python -m timeit "sum(range(1000000))"
    10 loops, best of 3: 71.5 msec per loop
    $ python3 -m timeit "sum(range(1000000))"
    10 loops, best of 3: 62.7 msec per loop
    $ python -m timeit "sum(xrange(1000000))"
    10 loops, best of 3: 26.6 msec per loop
    $ pypy -m timeit "sum(xrange(1000000))"
    10 loops, best of 3: 132 msec per loop

    $ pypy --version
    Python 2.7.1 (?, May 02 2011, 19:05:35)
    [PyPy 1.5.0-alpha0 with GCC 4.6.0]
    $ python --version
    Python 2.7.1
    $ python3 --version
    Python 3.2