Slashdot Mirror


World's "Fastest" Small Web Server Released, Based On LISP

Cougem writes "John Fremlin has released what he believes to be the worlds fastest webserver for small dynamic content, teepeedee2. It is written entirely in LISP, the world's second oldest high-level programming language. He gave a talk at the Tokyo Linux Users Group last year, with benchmarks, which he says demonstrate that 'functional programming languages can beat C.' Imagine a small alternative to Ruby on rails, supporting the development of any web application, but much faster."

502 comments

  1. "functional programming languages can beat C" by Jurily · · Score: 4, Funny

    In speed and elegance, perhaps. But not on the überprogrammer salary to maintain it.

    1. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 3, Interesting

      Dunno about you, buddy, but I find LISP a lot easier to read and write than all the C-like languages (although pure C itself is OK when it sticks to what it's good at - being a set of macros for assembler when programming systems-level stuff).

    2. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      In speed *or* elegance, since you can always disassemble their webserver and write C code that produces the same assembly. Highly inelegant C code, but same speed.

    3. Re:"functional programming languages can beat C" by epiphani · · Score: 5, Interesting

      No, definitely not in speed.

      He wrote a LISP-based memory-only webserver that could respond to requests roughly 10% faster than lighttpd with php. I promise you, if I wrote a C implementation that performed only the functionality he implemented, it would blow it out of the water. In fact, before anyone else comes out with the "X is faster than C!" claim, I'll leave the challenge out there:

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C. I leave this challenge out to anyone to take. (*)

      Seriously, I'm sick of this crap. Bring it on.

      (*) Caveat: It must be a small challenge involving a relatively simple task. I don't have a lot of time to waste on this.

      --
      .
    4. Re:"functional programming languages can beat C" by vivaoporto · · Score: 4, Informative

      Parent post is inflammatory but not troll. He has a point, this implementation is a minimal test case built in order to prove a point. A skilled C programmer could implement the same test case that would perform better than the LISP one, if the task was worthy.

    5. Re:"functional programming languages can beat C" by epiphani · · Score: 3, Insightful

      Modded Troll? Come on guys, its a legitimate challenge - I'd really love to have someone take me up on it. If anyone out there thinks they can honestly write faster code in some higher level language than I can in C, I want to put it to the test. It'll be fun, and I'll happily admit defeat if it can be thus proven. (And I'll take up the competing programming language.)

      --
      .
    6. Re:"functional programming languages can beat C" by Holmwood · · Score: 5, Insightful

      First, his blog is standing up to a slashdotting. That's impressive.

      Dunno about you, buddy, but I find LISP a lot easier to read and write

      Right, but we're not talking about you. I wish we were. If your skills were more common we'd have a better world.

      Second, I can speak up and I'm not even posting as an ac. It's straightforward to find people who can "program" in a language of their choice. It's tougher to find people who can program well in a language of their choice. It's tougher yet to find people who can program well in a language of your choice. It's very tough to find someone who can code well in C and insanely tough to find someone who can code well in LISP.

      It's been my observation -- as someone who has managed to convince many others that he deserves the salary of an "uberprogrammer" -- as I've shifted into running large engineering teams, that perhaps one in twenty programmers can code acceptably in C and perhaps one in two hundred in LISP.

      Third, I'd note there are behaviours of his software that surprised and annoyed some readers -- e.g. column treatment. I'd argue that these are generally buried deeper in LISP code than in C, but that's something we could heartily debate.

      Finally, his code seems typical of what I've seen from good LISP programmers -- including even at times myself. Poor documentation. The code is simple, elegant, and should "speak for itself". Well it doesn't. Not to someone trying to maintain it.

      C programmers -- perhaps because of the nature of the language -- seem less prone to this particular trap, though still bad.

      Regards,
      -Holmwood

    7. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 3, Insightful

      I think you are right that C can take on any higher level programming language in speed. The same could be said with assembly.

      The reason of course we don't write everything in low level programming languages is just the cost of maintaining them (LOC, readability, compatability...). I like what John has done in showing what assumptions should be made in a higher level programming language in order not to compromise a whole lot of speed.

    8. Re:"functional programming languages can beat C" by mauddib~ · · Score: 4, Insightful

      Yes, and your caveat is actually the most important element: for projects that need well definable high-level abstractions, or able to operate on mathematically infinite structures, a functional language wins clearly in comparison with C.

      The real question is: allow high profiled lambda abstractions, while keeping space and time complexity as low as an optimized C program.

      Well, just to show you that your challenge is easily met... In Lisp, it is easy to write an assembler, which over time allow the same kind of imperative abstractions as are present in C, thus allowing me to write a program with equal speed as in C.

      Also, when the nature of the input of a high-level programming language changes, it could optimize its data-structures and algorithms to create a better match with that input. Of course, such a thing could also be implemented in C or Pascal, but requires tremediously more effort.

      --
      This is a replacement signature.
    9. Re:"functional programming languages can beat C" by ID000001 · · Score: 1

      Why not go ahead and do a demonstration?

    10. Re:"functional programming languages can beat C" by Holmwood · · Score: 1

      This is not a troll, and should not be modded as such. The poster has an accessible (spam-protected) email address that I assume is valid. S/He's been posting a long time on slashdot, and his/her assertion is credible and interesting, albeit provocative.

      Moreover, I'm inclined to agree with my own caveat: while one can write C that is more rapid than LISP, one can also more rapidly write LISP than C (for a given problem).

      I also note my earlier statement, that it's easier (though still quite hard) to find a talented C programmer than a talented LISP programmer.

    11. Re:"functional programming languages can beat C" by K.+S.+Kyosuke · · Score: 1

      Wonderful. And after you write it, do not forget to send it to Jeffrey Mark Siskind. He will send you a faster implementation written in Stalin. :o)

      --
      Ezekiel 23:20
    12. Re:"functional programming languages can beat C" by epiphani · · Score: 1

      Nowhere in my statement did I say that C is therefor the correct language in which to write everything. As projects grow in size and complexity, maintainability is more important than raw speed.

      However, in context to the article, the example was "here is something that everyone does in C, but I did it in LISP and it was faster!" And that is my challenge: one, relatively small app written in any higher language will be faster when written in C. There are no restrictions to the challenge based on maintainability or number of lines of code.

      Willing to take up the challenge? :)

      --
      .
    13. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Aight. Please make http://shootout.alioth.debian.org/u32q/benchmark.php?test=chameneosredux&lang=gcc&id=2 execute more quickly than http://shootout.alioth.debian.org/u32q/benchmark.php?test=chameneosredux&lang=ghc&id=2 . Also, after you're done trying, please go and learn a bit about compiler theory, so that you know that C isn't a silver bullet of speed.

    14. Re:"functional programming languages can beat C" by imbaczek · · Score: 2, Insightful

      you can't be faster than C, because only C has access to complete 100% of special functionality OS kernels provide, like sendfile(). this challenge is moot and everybody knows it; the point is to _not_ be writing in C and achieve speeds which are respectable and/or fast enough.

    15. Re:"functional programming languages can beat C" by TheRaven64 · · Score: 1

      Probably true, but not necessarily interesting. You can take a high-level language, compile it to LLVM IR, and then use the C backend for LLVM, and get a C program which will be exactly as fast as the high-level language program. This effectively proves that the C program can always be at least as fast as the original program. The difference comes when you try to maintain it. Programs, over time, gradually accumulate changes, often far outside the scope of the original design. In a (good) high-level language, it is easy to make big changes and still have something that is fast.

      The problem with challenges like this is that they are effectively microbenchmarks, an area where low-level language do very well. In a microbenchmark, a C++ template or a C macro is much faster than a function call or a dynamic message send, for example, but they both increase code size, which increases instruction cache churn, and make the whole program slower. Using macros or inline functions in C makes your code faster when you benchmark a small example, but often makes it slower in a big program. To achieve the same level of flexibility without macros, you need levels of indirection via function pointers, and before you know it you've written a slow implementation of a dynamic language.

      The correct challenge isn't 'can you write a program in language X that is faster than the equivalent C program,' it's 'can you maintain a program for 20 years through three complete changes in requirements in C and still have it approach the speed of a written-from-scratch program'.

      --
      I am TheRaven on Soylent News
    16. Re:"functional programming languages can beat C" by rbarreira · · Score: 1

      In Lisp, it is easy to write an assembler, which over time allow the same kind of imperative abstractions as are present in C, thus allowing me to write a program with equal speed as in C.

      You can do the same in C, so the only conclusion from your argument is that neither is faster. Which makes the whole challenge useless if we go down that road.

      Of course, such a thing could also be implemented in C or Pascal, but requires tremediously more effort.

      Again this doesn't say anything about the intrinsic performance of a language.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    17. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Simple program: A small server that can be updated on the go, without being taken down, aka, code hot-swapping.

      I can do this in under 20 lines of code, I'll even have documentation there. Let me know when your C implementation is done, and we'll compare speed.

    18. Re:"functional programming languages can beat C" by bennomatic · · Score: 1

      Assembly's for wimps! I commit my code one bit at a time!

      --
      The CB App. What's your 20?
    19. Re:"functional programming languages can beat C" by stonecypher · · Score: 4, Interesting

      First, his blog is standing up to a slashdotting. That's impressive.

      Not unless you're used to desparately overburdened shared hosting. My six dollar a month account from HostMonster has handled multiple simultaneous slashdottings with concommitant reddit and digg traffic several times. One of my customers sustained roughly seven megabits of traffic for several days straight inside a VM with no problems.

      Slashdot traffic taking a site down means the site isn't hosted at a reputable host, these days.

      If your skills were more common we'd have a better world.

      As much as Lisp people want to say that Lisp lost because of the price of Lisp machines and Lisp compilers, it actually lost because it isn't a particularly practical language; that's why it hasn't had a resurgance while all these people move to haskell, erlang, clojure, et cetera.

      Lisp is a beautiful language. So is Smalltalk. Neither one of them were ever ready to compete with practical languages.

      It's very tough to find someone who can code well in C

      Er, no, it isn't. You just have to know where to look, and to not get stuck in the Silicon Valley highschool mindset, where nerf guns are believed to adequately substitute for health care, and where nobody can name a formal method.

      C programmers are the most numerous professional programmers on Earth today, and we're in the highest unemployment for programmers since the dot com bust, with a number of well meaning companies blindly ditching C for whatever the new hotness is (and eventually going right back). Hell, I get C/C++ programmers for things that aren't looking for C work, because they (rightfully) believe they can pick up the other language as they go and do a better job than the natives due to their understanding of actual costs.

      If you can't find someone who writes good C, either there's something wrong with how you're attracting staff, or you're not judging them skillfully, or they have some reason to stay away. I'm putting my chip on #3.

      --
      StoneCypher is Full of BS
    20. Re:"functional programming languages can beat C" by epiphani · · Score: 1

      Update exactly what code? I do this all the time using dlopen, if i need to.

      But your suggestion places a design constraint and does not define a functional requirement. I don't know anything about what I'm supposed to write. 20 lines of dlopen() wrappers?

      --
      .
    21. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      Dude, settle down. The primary difference in most cases between HLL and LLL implementations is still algorithm selection and structure. Write a static webserver that competes under load with YAWS and I'll be impressed; otherwise you're just another guy bragging.

      Incidentally, a static webserver is several hundred lines of C. It's an extremely simple task, and there's a well defined (and much more satisfactory) benchmarking set under Tsung that will laugh while your server withers under the heat of YAWS. You will not successfully compete with YAWS under the YAWS Tsung test set; timeslicing behavior is way too hard for anyone who would attempt to publically stage a meaningless, undefined "challenge" like this.

      As long as you haven't defined the task or the phrase "high level", you've left yourself enough wiggle room to exclude anything that's even slightly challenging. If you want to be taken seriously, produce the competing code, or at least _define_ what challenge you're making.

      And, frankly, dude, nobody really cares if you're sick of this crap until you've put up competition. (Don't bother tu quoqueing; I've actually released a webserver.)

      --
      StoneCypher is Full of BS
    22. Re:"functional programming languages can beat C" by RightSaidFred99 · · Score: 1

      You're right, of course. People like to come up with all kinds of crazy reasons why e.g. Java is "faster than C", when of course it's not. They come up with magic explanations like optimizations and memory management but of course they never quite understand if you wanted to you could make those SAME DAMN optimizations in C.

      That said - in most application domains it doesn't make enough of a difference to make up for the other advantages of a language like Java or C#/.NET.

    23. Re:"functional programming languages can beat C" by spydabyte · · Score: 0, Offtopic

      It's memorial day. Only people that work from home are on slashdot, amirite?

    24. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      In speed and elegance, perhaps. But not on the überprogrammer salary to maintain it.

      Über Pro Grammar? Isn't that what the /. grammar nazi's are always pushing on people?

    25. Re:"functional programming languages can beat C" by daveime · · Score: 2, Insightful

      Or perhaps we are part of the other 95% of the world that aren't American ?

    26. Re:"functional programming languages can beat C" by beelsebob · · Score: 4, Insightful

      The debian language shootout has a few examples of Functional languages being faster than people's best efforts in C, especially when it comes to parallelisation. I suggest you try and write a regex-dna example that's faster than the Haskell implementation for example.

      Having said that, the point really isn't that it's faster, it's that it's *as fast* - people should be shedding the ideas that functional languages are slow, and unusable, and trying them out in industry, because now the only real risk is that you have dumb coders (entirely possible).

    27. Re:"functional programming languages can beat C" by berend+botje · · Score: 1

      I'm sure nobody will call you on this one. It's obvious C has a lot of drawbacks compared to more modern languages. But for raw performance there isn't much that can keep up. I'm even willing to up the ante by saying that the solution in C will be at least twice as fast as the other competitor. And that is a conservative estimate.

    28. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      20 lines is small enough to post in this forum.

      Stop wasting our time saying what you "can" do and do it.

      If you really could do it you wouldn't have to boast as an AC.

    29. Re:"functional programming languages can beat C" by OrangeTide · · Score: 1

      But you don't make up 95% of Slashdot.

      --
      “Common sense is not so common.” — Voltaire
    30. Re:"functional programming languages can beat C" by Gorobei · · Score: 4, Interesting

      Actually, you can be faster than C in many cases. C must generate suboptimal code in certain cases because it cannot protect against edge cases like pointer aliasing.

      I've seen a LISP compiler generate better loop code in some cases, simply because it can prove arrays are non-overlapping, or that X*X is provably positive.

    31. Re:"functional programming languages can beat C" by MrMr · · Score: 4, Interesting

      Funny, I always say the same about fortran. Here's a toy test program for stuff I often need. I would be impressed when C beats this.

            program co
            implicit none
            double precision mpi
            parameter (mpi=3.141592653589793238462d0/1.024d3)
            double complex r(10240)
            integer i,j
            do j=10,110
               do i=-5119,5120
                  r(i+5120)=sqrt(mpi*i*j)
               end do
               write(j) r
            end do
            end

    32. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      No, it does not claim anything about the intrinsic (?) performance. I could claim the same for any Turing machine. Every computable function has a Turing machine equivalent...

      Also, it seems we're not discussing programming languages, but programming language compilers (implementations), the speed of which depend lineairly on the stupidity of the programmer making the compiler (slower = slower).

      --
      This is a replacement signature.
    33. Re:"functional programming languages can beat C" by Tablizer · · Score: 1

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C.

      How about a Lisp interpreter. It won't be faster than doing it in Lisp directly because Lisp already does it. At best it would match it.

             

    34. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 1, Interesting

      Your 'challenge' was already issued. From Git: "It is faster than all(?) other web application frameworks for serving small dynamic webpages. Please let me know if you have a case where another framework is faster!"

      Put up or shut up. No one's interested in trivial examples. That's what the great language shootout on Alioth is for, where C slacks more and more every year. Or from http://scienceblogs.com/goodmath/2006/11/the_c_is_efficient_language_fa.php :

      "I didn't know what language to use for this project, so I decided to do an experiment. I wrote the LCS algorithm in a bunch of different languages, to compare how complex the code was, and how fast it ran. I wrote the comp bio algorithm in C, C++, OCaml, Java, and Python, and recorded the results. What I got timing-wise for running the programs on arrays of 2000 elements each was:

              * C: 0.8 seconds.
              * C++: 2.3 seconds.
              * OCaml: 0.6 seconds interpreted, 0.3 seconds fully compiled.
              * Java: 1 minute 20 seconds.
              * Python: over 5 minutes.

      About a year later, testing a new JIT for Java, the Java time was down to 0.7 seconds to run the code, plus about 1 second for the JVM to start up. (The startup times for C, C++, and Ocaml weren't really measurable - they were smaller than the margin of error for the measurements.)"

    35. Re:"functional programming languages can beat C" by Gorobei · · Score: 1

      At least half the Wall St banks are using some form of functional programming for their front-office systems.

      It works if you can afford very skilled programmers. Unfortunately, most firms can't. Programmers are like lawyers: a few can talk at length about legal systems and theory, but most are only capable of routine divorce and tort cases.

    36. Re:"functional programming languages can beat C" by __aasqbs9791 · · Score: 2, Informative

      I dunno. This is what I saw when I tried to read it:

      "Service Temporarily Unavailable

      The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
      Apache/2.2.4 (Ubuntu) mod_fastcgi/2.4.2 PHP/5.2.3-1ubuntu6.5 Server at john.freml.in Port 80"

    37. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      It's memorial day.

      No, it's Memorial Day in the US.

      To the other 95% of the world's population it's just a normal day.

    38. Re:"functional programming languages can beat C" by __aasqbs9791 · · Score: 1

      Okay, where's your implementation of exactly what he (John) has done? I believe it should be possible, but if you are going to start a challenge like this you should prove you can do it by showing off your skills. If you do that you aren't a troll, and you have a very legitimate claim. But I don't see you proving anything, I just see the claim.

    39. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 1, Interesting

      how about beating Haskell in this benchmark: http://shootout.alioth.debian.org/u64q/benchmark.php?test=threadring&lang=all

    40. Re:"functional programming languages can beat C" by hibiki_r · · Score: 1

      The difference is optimization cost: Run time recompilation happens automagically in java 6: if the same branch of any loop happens to be hit 90% of the time, the VM will change its implementation for free, to make sure the right branch is in the pipeline already. You can technically do the same thing in C, but the effort required stops paying off quite quickly: C can theoretically beat Java every time if the programmer has infinite time and resources. In practice, it's faster many times, but sometimes it will lose.

    41. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Give me a LISP Machine or some other hardware that's nicer to Lisp implementations and it'll beat the crap out of a C implementation that runs on an x86.

    42. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 2, Informative

      The challenge is admittedly silly, but you can be faster than C.

      Reason 1: any language (which implements it) can make kernel calls. Many Lisp implementations, for example, have a way to make system API calls -- and this glue is usually implemented without any C. All you need to do is be able to pass arguments like a compiled C program would. No language has a monopoly on syscall 186.

      Reason 2: kernel functions aren't the ultimate in performance. There is plenty of functionality which can't be accessed by (vanilla) C, and in fact the kernel you praise so highly has many pieces written in assembler for just this reason. (Quick: how do you make a SSE3 call in ANSI C?) Fortress, for example, is built around the idea of parallelizing everything, including loops, which would be difficult to do in portable ANSI C and probably not be able to beat a language designed around that as its core feature.

      Reason 3: the Linux kernel (and probably others) tends to get faster over time. 2.6 is much more efficient than 1.0. ISTR that if your Lisp compiler was pretty fast (but a bit slower than C), a Lisp program using an algorithm that Linux 2.6 does will beat the Linux 1.0 algorithm in C. I doubt the Linux 2.6 algorithms are all (provably) optimal, so all you need is a better algorithm than what your kernel does. Cheating? I don't see it that way: a lot of algorithms I can write are pretty simple in Lisp, but mind-bogglingly complex in C. It would not surprise me in the least if somebody could come up with a much more efficient algorithm in Lisp that a C programmer would have to be a supergenius to come up with. I don't consider that cheating in this particular contest.

    43. Re:"functional programming languages can beat C" by iwein · · Score: 1

      You're right, we're the 95% that only reads this in their free time [citation needed].

      --
      Show a man some news, distract him for an hour. Show a man some mod points, distract him for the rest of his life.
    44. Re:"functional programming languages can beat C" by Docmach · · Score: 1

      How do you define the "intrinsic performance" of a language?

    45. Re:"functional programming languages can beat C" by mrops · · Score: 1

      What C programmers and programmers fail to realize it that there is something called time to Market, something called budget. An excellent example is iPhone. Even today, competitors have failed to relise why it sells and keep coming with iPhone killers. At the same time iPhone is gaining a market share that will give it dominance.

      This is where low level languages suck.

      I challenge you a bit differently, get 10 developers and code an enterprise level app with all the business/security requirement, do it in C, do it on budget and do it on time.

      This is where C is lagging behind.

    46. Re:"functional programming languages can beat C" by epiphani · · Score: 1

      I wanted to take you up on your challenge, but I was unable to do so. I know nearly zero about fortran, so forgive my ignorance.


      epiphani@cawk:~/chal$ fort77 -o ft ft.f
            MAIN co:
      epiphani@cawk:~/chal$ ./ft
      startio: illegal unit number
      apparent state: unit 100 (unnamed)
      lately writing sequential unformatted external IO
      Aborted

      --
      .
    47. Re:"functional programming languages can beat C" by dlakelan · · Score: 1, Informative

      As much as Lisp people want to say that Lisp lost because of the price of Lisp machines and Lisp compilers, it actually lost because it isn't a particularly practical language; that's why it hasn't had a resurgance while all these people move to haskell, erlang, clojure, et cetera.

      Lisp is a beautiful language. So is Smalltalk. Neither one of them were ever ready to compete with practical languages.

      The idea that LISP hasn't had a resurgence is wrong. Take a look at books published on common lisp recently. You'll see several from about 2004 to 2009. The SBCL project revived the CMUCL compiler in a cross platform and easier to improve way, which resulted in a large number of improvements. And places like common-lisp.net, clocc.sourceforge.net and cliki.net are the repositories for shared code in the free software community.

      There are several webservers written in common lisp, this is not the first by a long shot, and in case you didn't know, the technology inside orbitz is written in common lisp.

      The reason Common Lisp is not dominating the world is mainly that it takes a fair amount of sophistication to "get" the LISP way of doing things, and the huge availability of C based libraries.

      The popularity of Python is essentially about having a LISP that has a more familiar syntax and interfaces well with C programs. Python isn't LISP but it's not very far off.

      --
      ((lambda (x) (x x)) (lambda (x) (x x))) http://www.endpointcomputing.com a scientific approach to custom computing.
    48. Re:"functional programming languages can beat C" by phantomfive · · Score: 1

      Writing an assembler will probably only take a day. If you set that as the challenge, he'll probably take you up on it.

      Also, if you can think of a project that needs well definable high level abstractions, or is able to operate on mathematically infinite structures, I'll bet he'll take you up on it. Heck, I would.

      Define a problem and accept the challenge or you are just talk.

      --
      Qxe4
    49. Re:"functional programming languages can beat C" by debatem1 · · Score: 2, Informative

      1) The question is about functional programming languages versus imperative programming languages- not high-level versus low-level.

      2) Can we agree on a platform? If I get to name it, its going to be the Xerox 1109, and you're toast.

      3) The computer language shootout has some numbers that don't look so good for C. Maybe you'd care to re-implement the thread-ring test? Cause right now it's taking C 164+ seconds to do it, and 9 on haskell. Same thing on the k-nucleotide test.

    50. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      As much as Lisp people want to say that Lisp lost because of the price of Lisp machines and Lisp compilers, it actually lost because it isn't a particularly practical language; that's why it hasn't had a resurgance while all these people move to haskell, erlang, clojure, et cetera.

      Clojure is a Lisp.

      If you can't find someone who writes good C, either there's something wrong with how you're attracting staff, or you're not judging them skillfully, or they have some reason to stay away. I'm putting my chip on #3.

      Same is true of Lisp, BTW. We have regular FP get-togethers here, where we get together and show off cool things we wrote in Lisp in our free time, or for our employers without their knowledge. I know of zero companies hiring Lisp programmers in the Seattle area (and I've looked!). If you were a halfway decent business, you could have a couple dozen really great Lispers just for the asking.

    51. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      Most OS kernels export an ABI that can be used from any language. Linux is no exception.

    52. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Ok here's the challenge. Implement an equivalent of the lisp 'eval' statement.

    53. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      Same question as above- the computer language shootout, k-nucleotide and thread-ring tests. It's worth learning Haskell anyway ;)

    54. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      most languages have compilers made in C
      thus, writing the same routing in C = same speed (or faster)

    55. Re:"functional programming languages can beat C" by the+agent+man · · Score: 3, Insightful

      Is there a point to this challenge? I will prove that anything written in C will not be as fast as my implementation of it in assembler.

    56. Re:"functional programming languages can beat C" by Peaker · · Score: 1

      It must be a small challenge involving a relatively simple task.

      Once the task grows, it becomes pretty hard to write it in C, at which point people take shortcut that often harm performance.

      So you get an absurd situation that people choose C for performance but end up sacrificing performance because of the extra complexity of using C.

    57. Re:"functional programming languages can beat C" by phantomfive · · Score: 1

      Why would you be surprised? The compiler output for those two programs is going to be essentially identical, and there are two potential bottlenecks, the square root function, and the 'write' function. The speed of each implementation is going to depend largely on the quality of the square root function: so essentially you are asking if he can write a better square root function than your fortran compiler. Whether he can do so or not depends on which compiler you use.

      The write command can actually be a larger bottleneck, because it takes time to call the syscall, draw characters on the screen, etc. It will go faster in a terminal without scrollback, for example. So if you want it to go faster, you might consider putting the 'write' call outside of any loop, and also, if you use a different terminal than the standard console when you write fortran, it might go faster.

      However if you have instructions on which compiler you are using etc, I would be happy to at least try to beat it as well.

      --
      Qxe4
    58. Re:"functional programming languages can beat C" by gwait · · Score: 1

      Luxury! We used to dream of having bits to program!
      Try programming before zeros were invented - it was tough, but damn that software ran fast!

      --
      Bavarian Purity Law of Rice Krispie Squares: Rice Krispies, Marshmallows, Butter, Vanilla.
    59. Re:"functional programming languages can beat C" by MacJedi · · Score: 1

      (*) Caveat: It must be a small challenge involving a relatively simple task. I don't have a lot of time to waste on this.

      Nice caveat. Let me rephrase that another way for you: it is difficult to implement complicated functionality in C. Indeed, this is one reason to use higher level languages. You can achieve more in less time.

      --
      2^5
    60. Re:"functional programming languages can beat C" by mpcooke3 · · Score: 1

      If you know exactly what test case is being optimized for including the chipset etc, and you can feed profiling data to a static compiler for the test case then you probably will be able to beat any other high level language.

      But what if the task is to write the fastest implementation for any system where the test cases for the code, the CPU model and the system spec is not known beforehand. This is a more realistic test for a lot of software and it can be hard to beat a decent JIT compiler when you know so little about typical usage and the typical runtime environment.

    61. Re:"functional programming languages can beat C" by faragon · · Score: 1

      Why it should? Fortran is compiled, so it is C, and both are very simple and easily optimizable languages (GCC). Lisp can be compiled too, but by its flexibility still compiled implies higher overhead in parameter processing and more data cache trashing because of additional control structures requiring extra pointer usage.

      In the C vs Fortran you comment, the most time consuming is the complex domain square root (loop can be unrolled, integer multiply cand and FP integer load can be pipelined, along with FP multiply). Loop optimization, constant propagation, and strength reduction, can be done by both Fortran and C compilers, so there is no much left to be done (needless to say that the complex 'sqrt' implementation it is probably written in C).

    62. Re:"functional programming languages can beat C" by rbanffy · · Score: 1

      I take the challenge under the condition we measure time from start of implementation (disclosure of the problem set) until, say, a couple million pages are served from the test equipment.

      Given a sufficiently complicated set of functions, it's safe to assume that by the time the C code is running correctly, the HLL implementation will be days ahead.

      Circa 1987, I remember grades in numeric calculus clustered around two values, a higher one for the students who used BASIC-programmed CASIO calculators and a lower one, for students who used HP RPN-style programmable calculators. A higher level language is not an advantage I would give up lightly - the BASIC users were able to finish the tests with perfect grades in a third of the time their RPN counterparts. This motivated a rule change forbidding the use of programmable calculators in the following years in these tests.

    63. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      I'm not overly familiar with Fortran but the values you selected makes me think they're selected for a reason? Is there some reason a Fotran compiler would optimize this program?

      A couple comments about examples like this:

      1. This function uses a math routine sqrt() to do a lot of behind the scenes work. Math routines in particular are notorious for affecting performance based on the algorithm, processor specific optimizations, and special cases. So this particular example will be biased, possibly heavily, on that one function call.

      2. Challenges make much more sense in the context of a task to be performed rather than code for comparison. If a C coder deviated from your particular implementation too much you could easily claim "unfair". If you specify what the program must do you're better off.

    64. Re:"functional programming languages can beat C" by rrohbeck · · Score: 1

      First, his blog is standing up to a slashdotting. That's impressive.

      Not quite:
      Service Temporarily Unavailable

      The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
      Apache/2.2.4 (Ubuntu) mod_fastcgi/2.4.2 PHP/5.2.3-1ubuntu6.5 Server at john.freml.in Port 80

    65. Re:"functional programming languages can beat C" by ClosedSource · · Score: 2, Insightful

      "What C programmers and programmers fail to realize it that there is something called time to Market, something called budget."

      Perhaps, but this thread doesn't support the idea that C programmers "fail to realize" other issues. This is a discussion about speed, not time to market, cost, or maintainability.

    66. Re:"functional programming languages can beat C" by HiThere · · Score: 1

      The real answer is that speed of execution, while important, isn't usually the only deciding factor. It's quite often how easy it is to implement. I often choose a simpler implementation over a faster one, because the faster one isn't worth the effort. (Remember the 80-20 rule.)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    67. Re:"functional programming languages can beat C" by ClosedSource · · Score: 1

      For what it's worth, Lisp wasn't the language that most Xerox developers were programming for when using a 1109, it was Mesa. So perhaps Lisp isn't that fast on a 1109 after all.

    68. Re:"functional programming languages can beat C" by RegularFry · · Score: 1

      That's so unbelievably wrong, it's difficult to find anything right about it.

      --
      Reality is the ultimate Rorschach.
    69. Re:"functional programming languages can beat C" by HiThere · · Score: 1

      An optimal C implementation will not necessarily be faster than an optimal implementation in some other language...but it won't be significantly slower. (That usually means it won't be slower at all, but some other languages allow one to implement section in assembler, which can theoretically be faster than C.)

      However, the optimal C implementation may well be so complex that it never gets written. (As well as the optimal solution in any other language.) So this isn't a particularly relevant argument. One should deal with usual cases, and put a bounds around how sub-optimal you are. In such cases actual C implementations are frequently inferior to actual implementation of several other languages. Which is best depends on the problem under consideration. C is a very good language in many ways, but it has it's weaknesses. It's strength, which is hard for other languages to overcome, is it's breadth of libraries. Calling C libraries from other languages often adds in significant overhead, but many (most) languages have been forced to allow this because they just don't have the time to reimplement things from scratch. Callbacks make this especially tricky.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    70. Re:"functional programming languages can beat C" by HiThere · · Score: 1

      Make it a better challenge: Use arrays with multiple subscripts.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    71. Re:"functional programming languages can beat C" by MrMr · · Score: 1

      Ok, apparently fort77 doesn't do units above 99. just make the j loop 'do j=10,99'.
      Btw, I hope you're not running the f2c wrapper script called 'fort77'...

    72. Re:"functional programming languages can beat C" by Zagadka · · Score: 1

      So if I write a C compiler in [insert slowest language you can think of here] then C programs compiled with that compiler would be no faster than [insert slowest language you can think of here]? Sorry, no, that isn't the way it works.

    73. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      For what it's worth, Lisp wasn't the language that most Xerox developers were programming for when using a 1109, it was Mesa.

      Did not know that, I only ever used Interlisp on it- thanks for the info

    74. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      The OP's essential assertion was that C was going to be the fastest language at any given trivial task.

      As with all things optimization-related though, the answer is more complex than that. The odds are very, very good that I can pick a platform and a problem that combine to make C perform very badly compared to language x.

    75. Re:"functional programming languages can beat C" by MrMr · · Score: 1

      In this little test the difference is in the quality of the implementation of the square root of complex numbers.
      The write call is different for each j, they open 100 different binary files and write 10240 complex numbers to them
      There is no termial I/O.
      You can use any compiler you like; I compiled it with 'gfortran -O3 -march=i686 -o co co.f'

    76. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Today it was reported that GHC beats everything at the pidigits benchmark:

      http://shootout.alioth.debian.org/u32q/benchmark.php?test=pidigits&lang=all

      Would be interesting if you can beat that.

    77. Re:"functional programming languages can beat C" by 7+digits · · Score: 1

      Ok. Here is a simple Mathematica program:

      F[x_] := Length[FactorInteger[x]]

      F gives the number of distinct prime factors in x. For instance F[3] is 1, F[4] is 1 too (because 4 only have 2 as a factor] and F[12322] is 3 (12322=2*61*101)

      This is a small app. Write it in C faster than Mathematica.

      To give you a benchmark, an old Core2Duo take a little more than 2 seconds to answer to F[33622711352843762413542039873684935021017]

      (which is 2)

    78. Re:"functional programming languages can beat C" by laddiebuck · · Score: 2, Informative

      What's more without cache! That is, for every request, the PHP webpage is being recompiled. I hope he doesn't call that a fair comparison, as anyone even remotely interested in high throughput takes ten minutes to install a caching system like xcache or one of five other alternatives. I bet you anything that lighty, fastcgi and xcache would serve 1.5-2 times as many requests per second as his homebrew code.

    79. Re:"functional programming languages can beat C" by Kensai7 · · Score: 2, Insightful

      Every language has its own niche and ideal use.

      I like your simple example that shows the merits of the oldest high-level language in what it was designed to do best.

      --
      "Sum Ergo Cogito"
    80. Re:"functional programming languages can beat C" by MrMr · · Score: 1

      Unlike all other people in this thread, I thought it would be fun so see if the 'challenge' would be taken.
      Of course it's not a benchmark, it just a test how fast the system can compute and write a simple floating point expression.
      I'm not sure why you think 'challenges make much more sense in the context of a task to be performed' when the parent post specifically asks for a bit of code, but I'll bet you two beers that your abstract analysis of the relative merits of performance measures is not going be received well in a pub challenge.

    81. Re:"functional programming languages can beat C" by Actually,+I+do+RTFA · · Score: 1

      At what level is your challenge? Can a single function suffice? A whole program? I'm assuming your C code cannot devolve into calling ASM directly?

      --
      Your ad here. Ask me how!
    82. Re:"functional programming languages can beat C" by ratboy666 · · Score: 1

      Trolling sure sounds easy, but...

      Gambit-C Scheme vs. C

      I'll make it easy for you. It's the two minute litmus test. Even easier -- I'll give you the pseudo-C code:
      Task: compute n! for n >= 1000.

      In Scheme (Gambit 4.2.8, using infix):

      int factorial(int n) {
          if (n (load "f")
      "/home/user/f.o1"
      >(factorial 1000)
      4023...0000

      Your challenge? Write a C version in two minutes, tested and compiled. Now, as the final icing, run the C version on smaller numbers, and compare the performance -- did you forget to compile in small integer versions? (try factorial(12) a million times).

      I'll wait (another two minutes). Compare the performance against the LISP version. Did you have to write two versions -- one for big integers and one for small integers? That is pretty well the only way to keep a speed advantage... I hope you wrote it that way. Did you remember to put in 32/64 bit conditionals to retain your advantage on a 64 bit platform?

      I think your C code now looks like this (it should):

      #define FACT_LIMIT 12 -- for 32 bit int type, I don't know what the cutoff is for 64 bit.
      #include bignum.h -- I don't want to bother with quoting assume angle brackets /* This only gets executed a maximum of FACT_LIMIT times; leave it recursive */
      int fact_integer(int n) {
          if (n = 0) {
              return 1;
          } else {
              return n * factorial(n - 1);
          }
      } /* May wish to rewrite to an iterative form */
      bignum factorial(bignum n) {
          if (compare_lt(n, FACT_LIMIT)) {
              return int_to_bignum(fact_integer(bignum_to_int(n)));
          }
          return bignum_mult(n, bignum_dec(n));
      }

      You choose the bignum package to use. Or, for more fun, write it yourself. If you wrote it yourself, you remembered to switch to FFT style multiplication at bigger sizes? Or Karatsuba?

      Now, we have only coded to a recursive form, but, since bigints are not first-class in C, we don't know about memory reclamation (leakage). I hope you know the gmp library, or can roll up a gee-whiz allocator on your own. The gmp library would be cheating, by the way -- YOU DID CLAIM YOUR IMPLEMENTATION IN C.

      If recursion is viewed as a problem, the Gambit-C version can be recoded as:

      int factorial(int n) {
          int i;
          int a;
          if (n = 0) {
              1;
          } else {
              a = 1;
              for (i = 1; i = n; ++i) {
                  a *= i;
              }
          a;
          }
      }

      I am sure that something equivalent can be done in the C version. But the normal flow of control stuff doesn't know about bignums. We COULD make the incoming parameter an int, I guess... which works for factorial() but may not be as workable for other functions.

      Answers:
      - gmp does better than Gambit-C on bigint multiply, using FFTs.
      - breaking the result into two separate functions is needed for C to come ahead.
      - yes, C is faster, at the expense of a lot more programming.
      - if I want to, I can simply drop C code into my Gambit-C program on an as-needed basis. The Gambit-C code still looks a
          whole lot cleaner than the C version, and ties it for small integer performance. The bigint performance is still a "win" for
          gmp, but I can use THAT package directly as well in Gambit-C.

      Win:
      - Gambit-C. The prototype was finished to spec in two minutes. Optimizations can wait and are as implementable as in a native
          C version.

      Note that there is nothing non-LISP about Gambit. I chose it for this example because it has a infix notation available and is comfortable for C developers. There is nothing particularly special about the example either. It was chosen because it was small.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    83. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      The roomba is programmed in a lisp variant. Dozens of people have tried to make knockoffs that were certainly written in C. They don't work as well - the behavior of the robot is inferior because of the advanced architecture lisp allows.

      I not only maintain that you can't beat the speed of the software writing in C, I'd add that you couldn't even match the functionality without a high level language like lisp, without first writing a lisp interpreter.

    84. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      I think he was trying to get at the fact most compilers pre-process to C then compile - so are effectively C compilers themselves, just with an intermediate step.

    85. Re:"functional programming languages can beat C" by SnowZero · · Score: 1

      C must generate suboptimal code in certain cases because it cannot protect against edge cases like pointer aliasing.

      Aliasing is no longer a good example. There has been a "restrict" keyword since C99 came out, and it is supported in any modern compiler. There is also the type based optimization "strict-aliasing" which is enabled at O2 and above. Well written programs rarely use aliasing outside of esoteric helper functions, so the two compiler features solve the vast majority of cases.

      In my own programs, which manipulate arrays of similarly typed items in inner loops, "strict-aliasing" helps a bit, but I have never found "restrict" to help at all. While adding "restrict"s changed the generated assembly, performance effects were well within the noise of caching effects that one could evoke from just updating the program or changing link order.

      YMMV, but I avoid aliasing just because it makes programs easier to understand, and if a profile ever tells me I really need to look at a function, I can experiment with various flags that might help the optimizer to take advantage of that. Worrying about aliasing optimizations any more than that (such as porting to a new language) is not likely to be worthwhile IMO.

    86. Re:"functional programming languages can beat C" by setagllib · · Score: 1

      See -fstrict-aliasing, and the restrict keyword. You're welcome.

      --
      Sam ty sig.
    87. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      What about Meta-programming-- creating functions on the fly? This is easy in LISP, but would require so much extra machinery in C (parsing, linking, loading, etc.) that the corresponding C implementation would in fact be slower.

      My LISP is a little rusty, but here's a function that takes a function f as input and returns a new (tail recursive) function that iterates f n-times:

      (define (iter f n)
            (lambda (x)
                  (if (= n 0)
                          1
                          ((iter f (- n 1)) (f x)))))

    88. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      No need to "try them out in industry", Ericsson did just that with Erlang and wrote the world's largest functional program, all 1.25 million lines of it, to program the AX301 switch.

      Uptimes of "nine nines", i.e. 99.9999999%, which allows for ~31ms downtime a year.

      Do we really still need to argue in favoujr of functional programming languages?

    89. Re:"functional programming languages can beat C" by 32771 · · Score: 1

      Too sad that I have to read intel assembler again. Fortunately there is sse now.

      .L4:
              cvtsi2sd        %esi, %xmm1
              movl    $-5119, %edx
              .p2align 4,,10
              .p2align 3
      .L2:
              cvtsi2sd        %edx, %xmm0
              movl    %edx, %eax
              mulsd   %xmm3, %xmm0
              sall    $4, %eax
              mulsd   %xmm1, %xmm0
              incl    %edx
              sqrtsd  %xmm0, %xmm0
              cmpl    $5121, %edx
              movsd   %xmm0, r.917+81904(%eax)
              movsd   %xmm2, 8(%ebx,%eax)
              jne     .L2

      ...

      Aww, I can't be bothered, but that there is only one sqrt surprises me much. I wouldn't know how to do it without some time thinking about it, but I expect C to require a major effort to get something similar going.

      --
      Je me souviens.
    90. Re:"functional programming languages can beat C" by James+Skarzinskas · · Score: 1

      (security (job))

    91. Re:"functional programming languages can beat C" by Nevyn · · Score: 1

      Incidentally, a static webserver is several hundred lines of C. It's an extremely simple task.

      No, and no. It takes more than that to parse real HTTP messages, and that's assumeing you are using a sane string API (string.h, does not count IMNSHO).

      But then nginx, lighttpd, thttpd and even and-httpd should all be competitive if not outright beat YAWS (depending on what you test, the CPU and network speed). Then there's Tux aka. Red Hat Content Accelerator, and it just doesn't get faster than that ... for obvious reasons (but even then, both Tux and YAWS might hit the same wire speed wall ... IIRC you needed jumbo frames and 10Ge to start hitting Tux limits, a few years ago).

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
    92. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Ok. Nearly all systems these days have a GPU. I'll use CUDA and you can use C and we'll see who wins.

    93. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 2, Funny

      Cheater. C can beat all /real/ programming languages.

    94. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Wow, don't hurt yourself patting your own back. What is it about our field that attracts egos (especially those without the skills to back up their mouths). I've seen it for 30 yrs. We don't cure cancer but a lot of programmers are so egotistical. You write code for goodness sake! You think your such a 'leet hacker. Did you ever stop to think the reason you're good at it (assuming your not a loud-mouth with no skills) is because it is EASY. Writing code is not rocket science. Hell, I write code in my sleep.

    95. Re:"functional programming languages can beat C" by glenstar · · Score: 1

      Nice article, Justin. I figured you would be replying to this. :-)

    96. Re:"functional programming languages can beat C" by bertok · · Score: 1

      I would take you up on this challenge, but one of your original requirements is a problem:

      Caveat: It must be a small challenge involving a relatively simple task. I don't have a lot of time to waste on this.

      Of course it must be a relatively simple task! That's the problem with low-level but efficient programs. You trade off developer time for that efficiency. At some point, this can actually become counterproductive, especially for large, complex projects.

      For example, I used to code in C, C++, Java, Haskell, and these days I code in C#. I know full well that C/C++ are more efficient, give better control, and I know of dozens of techniques for writing ultra high performance real-time apps. I've even written a 3D game engine for a computer game, in C++, and it smoked.

      The thing is, I write all of my "high-performance" code in C# these days. I can't quite get the same performance as I could theoretically achieve in C++, but I can get excellent performance with a lot less developer time. It's trivial to write asynchronous code in C#, especially async IO, and farming things out to a thread-pool is one function call away. I don't have to worry about hideous problems like "when to free memory", which is hard enough normally, let alone in a multithreaded program.

      In a huge, complex project, if I can trivially make a segment of code multithreaded, it can get speedups of upwards of 10x on a modern server with a bunch of quad-core CPUs for a few minutes of my time. A modern JIT/VM language like Java or C# isn't 10x slower than C, so the overall result is a win.

    97. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 5, Insightful

      The popularity of Python is essentially about having a LISP that has a more familiar syntax and interfaces well with C programs. Python isn't LISP but it's not very far off.

      It is very far off. I'm not sure what criteria you're using to determine what's "not very far off", but if it's first-class functions, then most modern mainstream languages (with notable exceptions of C++ and Java) aren't "far off" from Lisp. But I would say that it's a wrong definition.

      What really sets Lisp apart is how the program itself is defined in terms of structures that are fundamental to the language, and how those structures can be easily manipulated in the language itself. Simply put, Lisp - especially Common Lisp (though R6RS is neat, too) - is a pinnacle of metaprogramming so far, and that's what is its defining feature. And Python doesn't come anywhere close to that.

      It's also what makes Lisp so hard to work. Yes, you can use macros to enable extremely high level of code reuse, effectively 100% (if theres any kind of pattern in your code, you can write a macro to encapsulate that). But it also means that you're effectively defining your own DSL, and then writing your program in that - and when someone else needs to understand and maintain your code, they'll have to figure out that DSL first.

      This isn't really fundamentally different from plain function/class libraries (they are also DSLs), but the expressivity of macros is so much higher than plain function calls (even with Smalltalk/Ruby style blocks and other such facilities) - and, consequently, so is their complexity. Idiomatic Lisp is invariably harder to understand than idiomatic C++, much less Python or Java.

    98. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 1

      But you don't make up 95% of Slashdot.

      By your logic, on Memorial Day, we do.

    99. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 2, Informative

      The debian language shootout has a few examples of Functional languages being faster than people's best efforts in C, especially when it comes to parallelisation. I suggest you try and write a regex-dna example that's faster than the Haskell implementation for example.

      First of all, you should be careful about using results from the Language Shootout in general, because they often don't know what they're measuring. For example, for quite a while, Haskell scored much higher on the benchmark because the tests were written in such a way that results were computed but then never used; and Haskell compiler is surprisingly good at figuring that out, so it discarded the whole computation part as well. In other words, Haskell tests didn't actually do the same work that C tests did. They've fixed it since then, AFAIK, but many articles on the Web that reference "Haskell beating C in the Shootout" are from before the fix. Here'a a much more realistic and interesting benchmark, in which Haskell didn't exactly do well (so far the best achievement is being 3 times slower than OCaml), despite the problem - ray tracing - being very well suited for functional languages.

      The other problem with Haskell is that it is very hard to tell how efficient your code is, both time- and memory-wise, from just looking at it. Because of the pervasive lazy evaluation, "neat" and innocent-looking code can be a performance deathtrap (that classic quicksort implementation in Haskell is one such example). It's extremely easy to get quadratic performance out of something that is defined in the simplest and most concise manner possible, and really shouldn't be more than linear.

      What matters is how well Haskell performs in real-world projects. Judging by how Darcs performs, it's pretty meh (how many projects have migrated off Darcs already because of performance reasons? heck, GHC team itself have dropped Darcs in favor of Git!).

    100. Re:"functional programming languages can beat C" by stonecypher · · Score: 3, Interesting

      That you believe several books over the course of six years constitutes a resurgence, especially given the historic nature of the language, kind of goes a pretty long way towards proving my point about its nearly non-extant market share.

      Don't get me wrong, I think LISP is a wonderful language. But, let's not do ourselves the disservice, please, of pretending that it's been a major player since the 1960s. If you look at the list of supposedly dead languages that majorly outpace LISP in real world usage measured either as new code or maintained code (eg Delphi, Clipper, Fortran, Cobol, PL/I, Ada, Forth, ANSI Pascal, Object Pascal, ColdFusion, pre-.NET ASP, all on both metrics) you get a clearer idea of where things actually stand.

      If LISP is so amazing, and if LISP has first mover advantage over anything the average programmer has ever heard of, why is it so resoundingly a bit player?

      There are downsides to LISP. Lots of them. Serious ones. It hasn't stayed this dead for 60 years because it's the tragic forgotten child of programming; every freshman who wants to sound educated thumps it at their first opportunity, frequently without ever having written a line (which is not to call you a freshman, just to point out how not-unknown it is.)

      It's a little like SICP. If it's been that free, that well known and that easily accessable for 20 years, how come it's being discarded by the university that published it for curriculum, and how come its design principles are largely unseen even in the work of people who have read it?

      There's a lot to be said for academic languages and academic exercises; they open our eyes to many new approaches to problems.

      But don't kid yourself. They died for a reason. Why is it that all the supposedly awful languages and design strategies are dominant?

      It's because they work. For all their warts, for all their maintenance problems, for all the infrastructure you have to write, they work.

      New practical languages are occurring which adopt many of the lessons of LISP. Ruby got a lot of LISP's problems removed, though it's still got a lot of problems of its own; Haskell can say the same. Erlang's got most of those problems cleared up, and is a practical real world language for a lot of things.

      But dude, if the most impressive thing you can find is the application of graph search to a complex web form with credit card processing that the typical college sophomore could throw together in about a month, I mean, I'm really not sure what to tell you. Orbitz is ridiculously slow for the amount of data it processes, its user interface is awful, it copes poorly with unexpected things like uncommon use of the browser back button, and I usually have to go to it first so that I can check everywhere else and then by the time I'm done everywhere else maybe Orbitz has finally finished its first search.

      What Orbitz does that's impressive is their ability to negotiate ticket prices. I go there because they get the bottom dollar bid. If that's your idea of something you can hold up to show the success of LISP, I've got to ask you: why have you gotten down to rare occasional me-too projects as your shining beacon?

      Yahoo! Stores was lisp too. (Note the past tense.)

      Big whoop.

      When it gets down to it, you should actually try writing something like that some time in LISP. Then try writing it in another language. It's not really all that different. It'll be maybe the dollar sign instead of the parentheses whose ink wears off on your keyboard, and the whatever other language you write will probably be somewhat bulkier (though if you're working in a language like Erlang, Haskell, Mozart-Oz or Forth, it'll be substantially shorter).

      Meh. Ten extra letters to get a three line algorithm done. Trade that for real exceptions and a strong type system, and you've chosen C++. Trade that for the pi calculus (which is hella more expressive than the lambda, and typically completely foreign to the LISPers who preach syntax superiori

      --
      StoneCypher is Full of BS
    101. Re:"functional programming languages can beat C" by Haeleth · · Score: 1

      Actually, it was also a public holiday in the UK, at least. (Google suggests it was in Lebanon and Ghana too, but those are less significant sources of Slashdot traffic.)

      Funny how an attempt to paint someone else as US-centric can serve only to show up your own ignorance of what's going on outside your own country ...

    102. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      There is currently no Haskell implementation of regex-dna. Challenge met.

    103. Re:"functional programming languages can beat C" by HiThere · · Score: 1

      Actually, an optimal C program would be nearly as fast as any other application. But it might be horrendously complex. You can't really pick a problem that an optimal C program can't do nearly as quickly as any other program, esp. when you remember that in C you can hack binary code into running. The reasons to choose other languages are rather different. Easier to use and understand are right up there.

      The obfuscated C competitions don't really give you any idea of what kind of gibberish an optimized C program can look like when it's handling a complex data structure. A result is that only mechanical optimization is common, and that's limited because the optimizer doesn't really understand what the program is doing. It would be interesting to see what a "evolutionary programming project" that operated on C source code would produce. I'd be willing to wager quite a bit that if it were optimizing anything complex, no human would understand the code in the first month. (Of course, it might take it quite a bit more than a month to write the code...) And the code STILL wouldn't be optimal!

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    104. Re:"functional programming languages can beat C" by Xiroth · · Score: 2, Interesting

      Finally, his code seems typical of what I've seen from good LISP programmers -- including even at times myself. Poor documentation. The code is simple, elegant, and should "speak for itself". Well it doesn't. Not to someone trying to maintain it.

      C programmers -- perhaps because of the nature of the language -- seem less prone to this particular trap, though still bad.

      Most likely because it's much easier to verbalise what a small segment of C is doing compared to a small segment of LISP. When writing C, I usually have a mental running commentary of what each line of code is doing. When writing LISP, I found that thinking about what it was doing in English was only stuffing me up, and I really had to let go of that kind of 'verbal thought' and think quite differently - in some ways more mathematically, but in some ways unique to functional programming. All this does make it a little more difficult to write comments for LISP, since 'shifting gears' to write in plain English is a much more difficult leap.

    105. Re:"functional programming languages can beat C" by Haeleth · · Score: 1

      Indeed. There's little point trying to compete with C on speed alone. Your C version will also almost certainly use less memory.

      The real point, however, is that your code would be written in a low-level language and his is written in a high-level language. In theory, this means that he will be able to add new features more easily than you can, and he will be able to use one language for everything, instead of one for the server and another for scripting. (I assume you will agree that C is not a great choice for web pages themselves, even with FastCGI?)

    106. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      You can do it for functional and logic/constraint languages, in terms of the number of runtime function applications or beta-reductions necessary to compute an algorithm. A language with the Hindley-Milner type system can perform computation at compile-time, and so can perform fewer run-time function applications.

      You can do this for procedural languages too...

    107. Re:"functional programming languages can beat C" by jbolden · · Score: 1

      What is that a test of.

      1) F[33622711352843762413542039873684935021017] converts instantly to
      2)Length[FactorInteger[33622711352843762413542039873684935021017]

      Which essentially takes the same time as
      3) FactorInteger[33622711352843762413542039873684935021017]

      Which depends on your FactorInteger routine which is coded in C in mathematica.

      That's not really a test of anything other than a very mature mathematical piece of software has good math libraries.

    108. Re:"functional programming languages can beat C" by poopdeville · · Score: 1

      First of all, you should be careful about using results from the Language Shootout in general, because they often don't know what they're measuring. For example, for quite a while, Haskell scored much higher on the benchmark because the tests were written in such a way that results were computed but then never used; and Haskell compiler is surprisingly good at figuring that out, so it discarded the whole computation part as well.

      That's called "lazy evaluation", and it is a language feature. It's the C program's fault for unnecessarily computing values it is never going to use, instead of computing them when demanded.

      --
      After all, I am strangely colored.
    109. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      No, and no. It takes more than that to parse real HTTP messages, and that's assumeing you are using a sane string API (string.h, does not count IMNSHO).

      I've written a fully HTTP 1.0 compliant webserver in C in 518 lines, using nothing other than the C and C++ standard libraries. Saying it isn't possible just means you don't know the difference between "can't" and "don't know how".

      You were the one who wanted a challenge. It's trivial to do; nweb is only 201 lines of code and it's HTTP 1.1 compliant. I can't imagine why you think it isn't possible just because you don't know how. For all the guff you seem to want to talk about how awesome you are in C/C++, you seem to be unable to actually accomplish relatively straightforward things.

      But then nginx, lighttpd, thttpd and even and-httpd should all be competitive if not outright beat YAWS (depending on what you test, the CPU and network speed).

      I cannot imagine under what fantasy this seems reasonable to you. YAWS spanks every one of those webservers; its only real competition in production is LightStreamer. You've never actually benchmarked any of these, have you? Just speculating, aren't you?

      Then there's Tux aka. Red Hat Content Accelerator, and it just doesn't get faster than that

      And you believe this why?

      ... for obvious reasons

      Which is handwave for "I have no idea what I'm talking about but really wish I did." I assume you think that anything running inside the OS must somehow by definition be faster than something running as an application outside the OS, which is laughably naive regarding where the actual limits in server scaling are.

      Until you have some idea how replacing a timeslicer would affect an application, you have no idea what you're talking about. No large scaling webserver uses the Linux (or for that matter the Windows) timeslicer; their design is aimed for a more general case usage. I'd be willing to bet you don't even know the growth rate of your scheduler. I wouldn't even be surprised to learn 1) that you have no idea what that phrase means, 2) that you think you do know what that phrase means, 3) that you can't understand why that's germane in a serving situation, and that 4) you're going to try to hold up this critical issue that you fail to understand as evidence of my failing to put together important pieces in the effort to cobble together an argument.

      Which is hilariously common among people who run guess driven argument as if it were fact, as you're doing.

      (I'm not even going to dignify your attempt to sound smart by dropping the wrong name for bandwidth caps as if it had anything to do with a discussion of webserver scaling. That's like mentioning gas tank size in engine fuel efficiency discussions: fundamentally retarded.)

      IIRC you needed jumbo frames and 10Ge to start hitting Tux limits, a few years ago

      You do not remember correctly. You should go look into PCI bandwidth to understand why people who actually do this stuff are currently laughing at you so hard.

      If you respond - and I confess I'm not looking forward to such a thing - do us both the favor of not making any arguments based on "obvious reasons", what you may or may not remember correctly, "should"-driven guessing. It's kind of boring. Stick to what you know well enough that you can give numbers, actual growth rates, case examples, studies or actual benchmarks.

      This speculation bullshit reeks of someone who's never even tried half the things they're discussing.

      --
      StoneCypher is Full of BS
    110. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 2, Interesting

      That's called "lazy evaluation", and it is a language feature. It's the C program's fault for unnecessarily computing values it is never going to use, instead of computing them when demanded.

      I know what's it called (in case you missed it, I called it that way in my original post), and I know it's a feature. But if you're measuring sort performance between two different languages, you have to make sure that either one actually, you know, performs the sort. It's good that Haskell compiler is smart enough to figure out the result wasn't used in the test, but it doesn't help you any to determine what the performance will be IRL when you actually do use the sort result.

    111. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      Clojure is a Lisp.

      And Objective-C is a Smalltalk, and Erlang is a Prolog, and Fortress is a Fortran, and etc. Indeed, in the exact same way that Clojure is a LISP, C++ templates are a LISP. If I had told him to move to C++, would you have said "C++ is a Lisp?" No: development in them is typically radically different.

      And they're all turing equivalent.

      You'll notice in another branch of this thread, I admonish someone that if they really need something lisp like, that they should move to a modern lisp, and gave a list of them including Clojure.

      Try re-reading what I said as if I knew Clojure's pedigree. Still makes sense.

      Incidentally, in discussions of language expressiveness, it's inappropriate to class 60-year descendant languages as the same as their parent languages. It'd be like arguing for the power of BCPL, then saying "omg C++ is a BCPL". Working in Clojure is a fundamentally different thing than working in LISP. For the same reason, I work in C++ but would not consider working in C or B; I work in ECMA but would not consider working in LiveScript; I work in Erlang but would not consider working in Prolog; I work in Clojure, but I would not consider working in LISP.

      LISP is nowhere near as expressive as Clojure. I would not pan Clojure; its usage is already almost caught up to LISP's, and for a damned good reason.

      Clojure is a LISP in the way that Islam is a Zoroastrianism. Heredity is not equivalence; if you spoke other languages you might be better equipped to understand that kind of novice error.

      Funny how you're using polymorphism to make your argument. And botching it.

      --
      StoneCypher is Full of BS
    112. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      That's exactly what I was thinking. Everyone who has performed mental gymnastics over this problem has failed to pull back and look at the big picture.

    113. Re:"functional programming languages can beat C" by countach · · Score: 1

      If you're going to have crappy code anyway, you're probably better off with crappy lisp than crappy C. Apart from anything else, there'll probably be less of it.

      And if you hire someone talented, they'll pick up Lisp just fine.

    114. Re:"functional programming languages can beat C" by poopdeville · · Score: 1

      Here's a happy challenge:

      YAML parser, C versus Haskell. No parser generators.

      This is a small challenge... I'll post mine once you post yours. Mine will be around 200 lines.

      --
      After all, I am strangely colored.
    115. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      Sorry, hit submit too early.

      I know of zero companies hiring Lisp programmers in the Seattle area (and I've looked!).

      Er, yeah that was kind of my original point, about LISP being dead. It's easier to find 16-bit Visual Basic jobs, FFS. Seriously: try looking for that.

      If you were a halfway decent business

      I own several, actually, two of them in software development. And they're more than halfway decent. LISP isn't generally applicable to any of our problem domains (hosting, gaming, iPhone applications, Flash applications, ad serving.)

      But I'm sure if I don't hire LISPers, my several businesses that you know nothing about must all be trash. (With an attitude like that, it's amazing to me you're employed in development at all.)

      you could have a couple dozen really great Lispers just for the asking.

      I'm a LISPer, actually. Funny how you discount that possibility. Also, many of the people I employ are LISPers. None of them write lisp at work, even though they're allowed to use any language for which there is an industrial quality implementation at a reasonable price, of which there are several for LISP. Several of them use Arc or Clojure, though very rarely. I'm unaware of any private projects going on in LISP at the moment, and I'd like to think I know my staff well enough that I know most of their projects, but it's possible I'm missing a few.

      I haven't written LISP in years. It isn't useful when you know other languages.

      Everything you say argues against the live-ness or viability of LISP in the modern era, except when you point to things that aren't LISP and curl them in by "is a lisp". C++, Objective C, D, Concurrent C, Java by way of Elm, C# and so on are all descendants of C, but if you pick any ten projects, you'd be lucky to find one whose natural implementation across any two of those is even similar.

      It's as absurd as asserting characteristics of America based on its being an England.

      --
      StoneCypher is Full of BS
    116. Re:"functional programming languages can beat C" by countach · · Score: 1

      There are many reasons why a programming language lives and dies apart from its intrinsic merit. For example, in days past C was popular because CPU cycles were a lot more important than they are now, and memory sizes were a lot smaller than they are now. Java was popular because it looks like C, but fixes some C problems. C# the same, C++ the same, Objective-C the same. TCL became popular because it was attached to a convenient Tk library. Ruby is becoming popular because of the web page library that made it famous. None of these reasons actually say much about the goodness of the language. They are accidents of history. I mean, that monstrosity of a language - Perl actually became popular. If that doesn't prove that popularity doesn't prove goodness, I don't know what does.

    117. Re:"functional programming languages can beat C" by jbolden · · Score: 1

      That's odd. Given how good the RPL was as a language for numerical computation I would have thought that the RPL guys beat the BASIC guys. It was effectively a higher level language.

      Any insight as to what caused the slowdown?

    118. Re:"functional programming languages can beat C" by Jerry+Coffin · · Score: 1

      Project: 64 Channel logic analyzer.
      Your Language: C
      My Language: VHDL


      Good luck!

      --
      The universe is a figment of its own imagination.
    119. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      Wait, so anything that is capable of producing the optimum set of machine code is optimal?

      By that logic, anything that can be used to execute arbitrary asm is optimal.

      Python can be used to execute arbitrary asm.

      So Python and C are both optimal, provided that the programmer using them is optimal.

      Therefore, Python is as fast as C.

      I love Python, but that's BS, and everybody knows it.

    120. Re:"functional programming languages can beat C" by countach · · Score: 2, Informative

      How many C programmers use "restrict" everywhere that it could be used? Zero point zero.

      Or how many use it anywhere at all for that matter? Probably like zero point one percent of programmers.

    121. Re:"functional programming languages can beat C" by Gorobei · · Score: 2, Interesting

      These certainly help, but are often hard-to-use in large programs: a low-level routine may declare it has restricted pointers, but it has no way to enforce that callers follow the rule. So, in big multi-developer systems, you tend to wind up with restricted pointer code kept in internal library functions, not exported functions, and the vast bulk of the app compiled defensively with full aliasing protection. Either that, or the app fails every other Wednesday for some strange reason.

    122. Re:"functional programming languages can beat C" by m50d · · Score: 4, Interesting
      It is very far off. I'm not sure what criteria you're using to determine what's "not very far off", but if it's first-class functions, then most modern mainstream languages (with notable exceptions of C++ and Java) aren't "far off" from Lisp. But I would say that it's a wrong definition.

      First-class functions, lambda, map and friends, generator expressions, and so on. My criterion is what it feels like to write, and in that sense Python is very close. (I'd go so far as to say it's better, but that's going to be contentious).

      What really sets Lisp apart is how the program itself is defined in terms of structures that are fundamental to the language, and how those structures can be easily manipulated in the language itself. Simply put, Lisp - especially Common Lisp (though R6RS is neat, too) - is a pinnacle of metaprogramming so far, and that's what is its defining feature.

      Lisp fans always claim this, but I think it's a red herring. TCL takes the same principle even further, and it's nowhere near as popular or admired. Metaprogramming isn't what makes lisp good to program in, it's all in the first-class functions and functional programming flow control tools.

      --
      I am trolling
    123. Re:"functional programming languages can beat C" by m50d · · Score: 1

      Sure, except that "fact" has been false for the last decade or so.

      --
      I am trolling
    124. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 2, Interesting

      First-class functions, lambda, map and friends, generator expressions, and so on.

      By those, virtually any functional language is Lispish - SML/OCaml/F#, Haskell, whatever.

      Also, C# 3.0+ would be Lispish (it has everything that you've listed), as well as Scala.

      Lisp fans always claim this, but I think it's a red herring. TCL takes the same principle even further, and it's nowhere near as popular or admired.

      What does it have to do with being "popular" or "admired"? It is, in general, pretty widely acknowledged in the PL community that Tcl is indeed one of the languages close to the spirit of Lisp, though not its syntax.

    125. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Java *was* popular? I guess you haven't looked for job offers recently.

    126. Re:"functional programming languages can beat C" by ciggieposeur · · Score: 1

      Does his homebrew code have a cache too? Because if not, he can very easily add it and be beating cached PHP again.

    127. Re:"functional programming languages can beat C" by SanityInAnarchy · · Score: 1

      I think you are right that C can take on any higher level programming language in speed. The same could be said with assembly.

      I don't agree. There are things Lisp interpreters have done that C compilers really haven't, in terms of optimization. I wouldn't say Lisp is faster than C, but nor would I say that any higher-level language must necessarily be slower than C, so long as it's actually C, without inline assembly.

      On the other hand, all languages end up either being interpreted, or compiled to assembly. Or directly to binary, but assembly is essentially a human-readable representation of binary. Therefore, you physically cannot beat assembly, given sufficient time for a human to tweak the program -- the best you could do is tie it.

      --
      Don't thank God, thank a doctor!
    128. Re:"functional programming languages can beat C" by a-zA-Z0-9$_.+!*'(),x · · Score: 1
      Oh yeah? OK, invert a matrix in C, and then in APL (or J). Make the C program accept binary, integer, single precision or double precision arrays, real or complex numbers.

      Try programming:
      sin=: 1&o. NB. Function to be approximated
      x=: 5 %~ i. 6
      c=: (sin x) %. x ^/ i.4 NB. Use of matrix divide

      tOM

      --
      Epitaph: At last! Root access!
    129. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      The point is to establish the speed hierarchy: assembler > C > higher-level language. If you already believe it then it won't do much for you, but in today's story a fool claimed LISP > C and that was annoying.

    130. Re:"functional programming languages can beat C" by SanityInAnarchy · · Score: 1

      I wouldn't agree with that.

      For instance, Java does not have an ideal use. PHP may have, once, but now that most major languages have associated templating systems -- most of which are better -- PHP really doesn't have an ideal use anymore.

      Of course, every language has an "ideal" use if you count maintaining old crap written in that language...

      --
      Don't thank God, thank a doctor!
    131. Re:"functional programming languages can beat C" by Raffaello · · Score: 1

      This whole thread screams that C programmers spend far too much time thinking about raw execution speed, and far too little time thinking about time to market, maintainability, etc.

    132. Re:"functional programming languages can beat C" by da+cog · · Score: 1

      While your point is well taken that one needs to take the Language Shootout with a grain of salt, on the other hand you have presented a benchmark that is over a year old, and the compilers have been evolving a *lot* since then, so it is probably *less* likely than the current language shootout to give a sense of relative speeds. Having said that, as another post has already mentioned, it is rather damning to the grandparent's case that Haskell currently doesn't actually have a compiling regex-dna solution posted on the Shootout. :-)

      Also, I am not sure that Darcs is a good example because, as I understand it, the problem is not that it was written in Haskell, but that it uses its own unique algorithms based on an "algebra of patches" that tends to run slowly in practice, and in particular it has worst-cases scenarios where it runs in exponential time.

      --
      Snarkiness is inversely proportional to wisdom because it emphasizes feeling right rather than being right.
    133. Re:"functional programming languages can beat C" by PRMan · · Score: 1

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in ASM. I leave this challenge out to anyone to take. (*)

      --
      Peter predicted that you would "deliberately forget" creation 2000 years ago...
    134. Re:"functional programming languages can beat C" by 7+digits · · Score: 1

      And your point is ?

      The challenge is, verbatim: "And that is my challenge: one, relatively small app written in any higher language will be faster when written in C".

      So, you think to think that, because FactorInteger is coded in C, it should not be used. Then what about that simple program ?

      G[f_] := Integrate[f, x]

      You pass it a function f, and it integrates it. And no, Mathematica's Integrate is NOT written in C.

      Or maybe I can't do that, because I relie on "good math libraries" ? Rules out an option pricer, then. And I guess I cannot post any Prolog program that uses unification too ? Because that is hard to do in C.

      If one morph the challenge into "write a simple app that don't take advantage of anything that would be long to reproduce from scratch with a C compiler", OF COURSE, it can be rewritten in C, even if it is a bit longer and unmaintainable.

    135. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      Yes, but that's for 'an algorithm' (quote). How do you define it for a language? I thought that this is impossible with our current computational maths applied to Turing complete languages (with proof).

      --
      This is a replacement signature.
    136. Re:"functional programming languages can beat C" by HiThere · · Score: 1

      Anything that CAN execute arbitrary ASM as native code CAN be optimal. Doesn't guarantee that it will be. Python can never be optimal, because of the overhead of the interpreter, but if most of the work happens in C coded libraries it can be quite fast enough.

      I like Python too, but I sure didn't make the argument that you read. If I had I'd be coding my current application in Python instead of picking up C++. (Of course, if I had a large chunk of native binary that would do just what I want, then Python probably would be fast enough, but that's not an extant condition.)

      P.S.: When I'm talking about executing arbitrary ASM code, I'm not talking about interpreting it, I'm talking about assembling it and executing it. Some languages that I know can do this are Forth and D. I believe that some dialects of C also have this built in. (I know they used to, but the last time I paid attention to this it was C running on a CP/M system. I don't believe that it's a part of standard C, but I could be wrong. When I said C could be hacked to execute binary I meant you could load arbitrary binary in from a file and then call it as a function. If you do it just right, you can make it work. Since this is only needed for very small pieces, like testing processor flags, etc., it's not a totally impossible thing to do. It's better to use a separate assembler routine, but it's not necessary, and I wanted to make a point that it was ultimately flexible in running self-modifying code. Also that such a thing was so complex and dangerous that there's probably never a decent reason to do it.)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    137. Re:"functional programming languages can beat C" by jbolden · · Score: 1

      My point is if you want to test coding benchmarks don't ask for a test that does nothing more than invoke a library. Your Integrate example is a little better but you are still just using a library.

      Something like cram game is what you would want to test.

    138. Re:"functional programming languages can beat C" by cstacy · · Score: 1

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C.

      I recall a shootout in 1994 where the problem was in Genetic Programming; the result was that Lisp slightly beat GCC. I believe there are plenty of other (and more recent) examples which are of more mundane things where Lisp nearly matches, matches, or exceeds the performance of C programs. I think I saw one involving simple string manipulation recently where Lisp beat C due to poor assumptions by the compiler about memory alignment or something. My memory is a hazy about all these details because Lisp is always fast enough and C is otherwise unsuitable to the problems I work on.

      Bring it on.(*) Caveat: It must be a small challenge involving a relatively simple task.

      If your claim is merely that you can, by constraining the problem to something suitably trivial, come up with programs in C that are faster than Lisp (or whatever), then I have no doubt that you will in some cases be right. (You might be right less often than you expect, though, because compilers are probably smarter than you think you are.)

      If you are concerned only with certain trivial programs and the performance thereof, that's fine, but that's not interesting to most people who consider programming in Lisp. This reminds me of the LISP/FORTRAN benchmark shootouts from about 1974 where we got sick of people saying that Lisp wasn't good for numerical programming. So the compiler developers spent a month tuning the MACLISP compiler for math, and then LISP was beating FORTRAN all the time after that.

      Note also that it makes little sense to compare the speed of languages - you are always comparing the speed of particular implementations (compilers). People usually pick GCC for C, of course. And lots of languages today are single-implementation languages. But Lisp is an ANSI language standard that has lots of (open source and commercial) implementations. (Well, and there are also a number of other Lisp dialects that are not the ANSI one, with all their attendant implementations. In fact, I am sure that I could create a Lisp implementation that will beat whatever C shootout problem you would like to propose to prove your point that one language is faster than another, for that matter. I don't think it would prove anything useful except that your assertion is misguided.)

      As for comparing web server performance, there are lots of issues to consider. I didn't read TFOA - not that interested as I already have Lisp-based web servers I like.

      By the way, web servers in Lisp are nothing new, they were out there from the beginning. A super-fancy server called CL-HTTP was in use before PHP was invented, for example. There are quite a few web servers written in Lisp, some attached to Apache or IIS, and many as complete standalone servers. Now apparently some dude has coded up a server that outperforms some other server according to some metrics. Yawn.

      When I find that my servers are running too slow, I just buy another server. Because they're never running so slow that this is unreasonable. The performance of the Lisp based servers is always comparable to the alternatives in my experience.

    139. Re:"functional programming languages can beat C" by XDirtypunkX · · Score: 1

      Probably because in many of the domains that C programmers currently work in raw execution speed is an extremely important aspect of the marketable product. If they were working on need-it-yesterday enterprise systems where the database is the bottleneck anyway, then they wouldn't be using C.

    140. Re:"functional programming languages can beat C" by debatem1 · · Score: 1

      Anything that CAN execute arbitrary ASM as native code CAN be optimal. Doesn't guarantee that it will be.

      That's exactly how I characterized your argument, and it's every bit as wrong now as it was then, for two reasons: 1) using another language to load ASM will inherently produce non-optimal machine code, it's only a question of 'by how much', and 2) it doesn't actually say anything about *that language* except how quickly it can load ASM. The point of my previous post was that your logic led to a factually untenable position.

      The point here is, asking how fast a language is is pretty much the definition of premature optimization- certain classes of languages are generally going to perform certain tasks faster than others, and inside those classes there are ways to jockey for position, but anything else is just a a nicer-sounding way of saying 'I don't know how to optimize language X'.

    141. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      C really isn't that great.
      See here for some info on C perf from a googler, and FFTW for the fastest code around for doing FFTs.
      In both cases, Objective CAML (a high-level and functional language) smokes C. Both are in areas (in particular FFTs) where people have been optimizing implementations for decades.

    142. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      http://shootout.alioth.debian.org/u32/benchmark.php?test=threadring&lang=all

      OK, go on. Do this in less than 100 sec to beat the best C entry.
      Do it in less than 8 sec to prove your point.

      Unless

              * create 503 linked threads (named 1 to 503)
              * thread 503 should be linked to thread 1, forming an unbroken ring
              * pass a token to thread 1
              * pass the token from thread to thread N times
              * print the name of the last thread (1 to 503) to take the token

      Is too complicated for you

    143. Re:"functional programming languages can beat C" by speedtux · · Score: 1

      The popularity of Python is essentially about having a LISP that has a more familiar syntax and interfaces well with C programs. Python isn't LISP but it's not very far off.

      It's not that simple. Python is like early Lisp: simple, powerful, doesn't get in your way, but also really inefficient and dumb. Like early Lisp, it has numerous limitations: poor performance of the compiler and garbage collector, lack of multithreading, and lack of a clear language definition and standard.

      CommonLisp's problem was that its developers spent way too much time trying to get things "right" (for some definition of "right"), and they missed the boat on many things that actually matter. So, CommonLisp implementations tend to have excellent garbage collectors and good compilers, but then ther are often also have really weak parts of the implementation anyway (floating point, arrays, etc.). And CommonLisp designers also didn't like the way UNIX did things, so they rather came up with their own better abstraction, which basically killed their use in most real-world projects.

      As with all languages, once a language heads down a particular track, people whose needs it doesn't meet just leave quietly and pick something else.

      A revised CommonLisp with some of the rough edges smoothed, obsolete packages removed, Unicode through and through, byte-oriented I/O, and standardized threads, C interfaces, and I/O would be a good and competitive language, but it doesn't have any buzz. But I suppose stranger things have come back from the dead, so it's possible.

    144. Re:"functional programming languages can beat C" by goban19 · · Score: 1

      Sure. How about pi digits http://shootout.alioth.debian.org/u32q/benchmark.php?test=pidigits&lang=all . Currently the fastest program is in the functional language Haskell. I challenge you to write a faster one in C (for a quad core processor).

    145. Re:"functional programming languages can beat C" by bill_kress · · Score: 1

      This seems to be one case where C could use some help:

      http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=all&box=1

      The functional languages seem to have it locked up, or perhaps their C implementation needs you to step up and fix it.

      There is no reason any other compiler couldn't put out code as good as C, better in fact since C allows pointers (which stops the compiler from making quite a few optimizations). It's just that C tends to be easier to hand-optimize right now (just like assembly is easier than C). That doesn't make assembly better for 99% of the cases though, and the same could be said of C.

    146. Re:"functional programming languages can beat C" by MrMr · · Score: 1

      Odd bit of code. I would expect to see a MOVDDUP instruction for the complex number math in sse. Did this actually work?

    147. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      No, definitely not in speed.

      For delivering dynamic pages, yes, of course, you can beat C in speed! The key point here, is that you don't want to use C to generate the dynamic contents. You want use another (probably higher level) language. The penalty you will have to pay to cross the languages boundary will be so huge that all the benefit of having the server implemented in C will vanish.

      For that very reason, Tomcat/JSP delivers dynamic content faster than {Lighttpd,Apache}/{php,perl}. Bootstrapping the server in the language used to generate the contents might be a big win. This has nothing to do with functional languages vs C (although functional languages now have strong and fast implementations).

      Those interested by fast bootstrapped web servers might have a look at the paper found at:
      http://discotec09.di.fc.ul.pt/index.php?title=Coordination/Invited_Speaker

    148. Re:"functional programming languages can beat C" by OrangeTide · · Score: 0, Flamebait

      You don't make up 95% of Slashdot either. So did you have a point?

      --
      “Common sense is not so common.” — Voltaire
    149. Re:"functional programming languages can beat C" by SlashWombat · · Score: 1

      The code is simple, elegant, and should "speak for itself". Well it doesn't. Not to someone trying to maintain it.

      I hate this ... the crap you hear about code maintenance from those who think they know better. Good code is good code, whether or not it has "good comments". If the idiot employed to maintain it can't follow it, this does not mean it's bad code, it means the maintainer is nowhere near as intelligent as the original programmer. (Little wonder that person no longer works your company ...).
      So what happens ... the smart, well written code that executes quickly gets replaced by crappy (probably very buggy) code, but gee whiz, the halfwit manager who does the code reviews can now follow it, so it must be better!
      Believe me, I have watched this happen so many times its not funny. Code originally written by 2 or 3 people gets maintained (in the end) by teams of 20 to 40 people. Code gets slower, code gets bloated, code gets very buggy, but hey, look, the managment are proud of how maintainable it is!

    150. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Challenge: to write a very basic LISP interpreter, in LISP and in C, compare reliability and performances.
      Last time I wrote a LISP interpreter, it was using Z80 machine language, it was 24 years ago and it took me two nights.
      Specs: must be able to manage integers and ASCII strings as built-in types, and standard car, cdr, cons, cond, eq, and of course, lambda.
      Two native types, one single structure for data and program and six functions to implement.
      Is the challenge small enough for you?

    151. Re:"functional programming languages can beat C" by rbanffy · · Score: 1

      I think RPL appeared after the 41s. By the time the 48s started showing up, I was graduating.

    152. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      Sure there is, and it's 2-3 times faster than the C version.

    153. Re:"functional programming languages can beat C" by rbarreira · · Score: 1

      This whole thread screams that C programmers spend far too much time thinking about raw execution speed, and far too little time thinking about time to market, maintainability, etc.

      Really? I thought the thread was about programmers who love other languages claiming they have better performance than C.

      It would be the same as if a C programmer claimed that memory management is easier in C than Java.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    154. Re:"functional programming languages can beat C" by LSD-OBS · · Score: 1

      Just a heads up, you've truncated pi instead of rounding it off — the next digit is 6. No, I didn't just look that up :(

      --
      Today's weirdness is tomorrow's reason why. -- Hunter S. Thompson
    155. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      I find your whole comment rather odd. You're essentially saying "it's not fair, the Haskell compiler optimises code better than the C compiler does". The Haskell compiler has recognised that the task it's being asked to do does not require everything to be evaluated, and hence is optimising that code away.

      The bottom line is if you're asked "produce this output", and you do so then it's entirely valid. The fact that Haskell is amenable to massive optimisation like that is something the shootout should be demonstrating.

      And to fire back at the "unfairness" of the shootout, Haskell has been banned from putting a pragma in some of its programs that specifies how the garbage collector should behave. Why? Because when that's done, the code runs 4 times faster, and beats C.

    156. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      Sounds like an imperative programmer talking: you 'use' the sort. As if it is a certain step in a program, instead of something that can be interleaved with other calculations.

      --
      This is a replacement signature.
    157. Re:"functional programming languages can beat C" by jbolden · · Score: 1

      RPL came out with the 28c in 1987. I personally used a 28s starting 1988. We are talking around the same time since the 48s came out when I was a junior. If they were using something like a 15c compared to a Casio, yeah I can imagine there would have been a difference.

    158. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      Your challenge is met conceptually:

      1. Write an assembler in Lisp, changing a list of instructions to their binary equivalents (eg:
      ( (MOV AX, BX), (SUB AX, 1) ) => binary
      2. Write an imperative language in Lisp, which translates to machine language
      (eg. ( ( decl 'int ( symb "a" ) 5 ) ) ).
      3. Write your problem in the language of 2, and generate machine language
      4. Execute it

      In this way, my program is *always* of equivalent performance, compared with yours.

      --
      This is a replacement signature.
    159. Re:"functional programming languages can beat C" by h4rm0ny · · Score: 1


      Comments should be appropriate. A recent project of mine doesn't have comments at every control structure explaining what any competent programmers can see is going on. (And a competent programmer should see for themselves what is actually going on, not what the comments tell them is supposed to be going on, but that is another discussion).

      However, several of the class files begin with a few paragraphs of explanation clarifying the naming convention I have used for variable and function names throughout (example, I use 'module' to refer to educational units in the external system and 'course' to refer to educational units in the internal system so that if you see a function called map_courses(...), you know what it's referring to). The comments also sometimes contain design notes to explain why I chose a particular solution, etc.

      Bad comments are redundant or wrong / out of date. Good comments are a boon to people who inherit your code and need to hit the ground running.

      --

      Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    160. Re:"functional programming languages can beat C" by SL+Baur · · Score: 1

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C. I leave this challenge out to anyone to take. (*)

      Seriously, I'm sick of this crap. Bring it on.

      That's what programmers said 50 years ago s/C/Assembly/. IBM proved them wrong with a FORTRAN compiler.

      I think I could do the same thing you described[1]. I have every doubt that the folks sitting around me in adjacent cubicles could do so. That's kind of the point.

      [1] Things aren't so simple now with the way CPU manufacturers are designing chips - http://lwn.net/Articles/250967/

    161. Re:"functional programming languages can beat C" by ultranova · · Score: 1

      I hate this ... the crap you hear about code maintenance from those who think they know better. Good code is good code, whether or not it has "good comments". If the idiot employed to maintain it can't follow it, this does not mean it's bad code, it means the maintainer is nowhere near as intelligent as the original programmer. (Little wonder that person no longer works your company ...).

      So if code is commented, it's easier to figure out what it's doing, and to alter this function as desired. That's pretty much the definition of maintainability. I guess that means those people who asserted that really know better than you. Furthermore, since you simultaneously disagree with them and prove them correct, guess who comes out as the idiot here?

      So what happens ... the smart, well written code that executes quickly gets replaced by crappy (probably very buggy) code, but gee whiz, the halfwit manager who does the code reviews can now follow it, so it must be better!

      Believe me, I have watched this happen so many times its not funny. Code originally written by 2 or 3 people gets maintained (in the end) by teams of 20 to 40 people. Code gets slower, code gets bloated, code gets very buggy, but hey, look, the managment are proud of how maintainable it is!

      And all that could had been avoided if the 2 or 3 people who wrote it in the first place would had bothered commenting it! I guess that explains why the management wants comments.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    162. Re:"functional programming languages can beat C" by DuckDodgers · · Score: 1

      All through college, I was taught that CPU cycles are cheaper than developer man-hours. And clearly, computers are far cheaper today relative to the cost of a good developer than 30 or 40 years ago.

      But look at the world today. We have software running in VMs, software on cell phones, all sorts of embedded devices, and netbook PCs with relatively anemic resources. Our workstations have dozens of services and background processes running. And in terms of server applications, you also have to consider that one fast application running on one server saves you a lot of configuration, concurrency, and backup headaches compared to clustered applications on multiple servers.

      Efficient code still matters quite a bit. It's not the end-all-be-all like it was in the infancy of computing. But it's not something you can ignore either.

      Perl became popular because all of its syntactic shortcuts and builtin language features permitted extremely rapid development. It's the anti-C: often 10 times faster to write, almost always 100 times slower to execute. When that tradeoff makes sense, it was very suitable. Since then, you can argue that Python and Ruby have taken all of the best ideas of Perl and left behind the ones that made it too easy to write unreadable code. But Perl is still a very useful, usable language - especially when you follow recommended convention.

      And "Java was" nothing. Love it or hate it, Java is the biggest programming language in the job market today or very close to it. It might be growing at a reduced rate or maybe even shrinking slowly, but we're easily a decade away from seeing it become uncommon. It's not touted much for the desktop, but the language is good enough for server application purposes.

    163. Re:"functional programming languages can beat C" by Axman6 · · Score: 1

      I'd quite like to see you beat my Haskell entry for the computer language shootout, thread ring program: http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=all&box=1 it's currently almost 20 times as fast as the C entry. If you can beat it, then please, by all means, submit it to the shootout, just make sure you read the rules (there may be faster ways to do the same thing, but separate threads of execution are required) :)

    164. Re:"functional programming languages can beat C" by ultranova · · Score: 1

      However, in context to the article, the example was "here is something that everyone does in C, but I did it in LISP and it was faster!" And that is my challenge: one, relatively small app written in any higher language will be faster when written in C. There are no restrictions to the challenge based on maintainability or number of lines of code.

      Suppose we remove the condition "relatively small app". Suppose we start the challenge by writing small and simple apps, and make them progressively larger and more complex. How long is it going to take until your C programs become buggy and slow simply because you don't have time to debug and optimize them?

      Assembly is the fastest language there is if you have infinite time to optimize the program. Once you remove that assumption and impose some reasonable limit after which it has to be done, most programs will be slower when written in assembler. The same happens to C, thought it will hang in there longer; and it'll happen to every programming language. That's one of the reasons why we're moving to higher-level languages: those languages are faster than lower-level languages for programs with complexity greater than some limit.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    165. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Oh snap, Google sent me to the Gentoo Pentium 4 page instead of the x64 Ubuntu Q6600 quad-core one.

      Ok so it's 2.3x faster because it's using 4 cores while the C version is using only one. Doesn't seem insurmountable to me.

      regex-dna C GNU gcc #2 program
      N CPU secs Memory KB Size B Elapsed secs ~ CPU Load
      5,000,000 31.33 124,776 1099 31.32 100% 0% 0% 0%

      regex-dna Haskell GHC #4 program
      N CPU secs Memory KB Size B Elapsed secs ~ CPU Load
      5,000,000 37.69 188,316 1672 13.55 89% 60% 61% 65%

    166. Re:"functional programming languages can beat C" by rbanffy · · Score: 1

      They were using mostly 41s at the time I took that course, so, I guess it happened before the 28.

    167. Re:"functional programming languages can beat C" by 7+digits · · Score: 1

      The issue with the cram game, is that Ia m pretty sure I can code it in C and have it faster than the Mathematica version, so that would make it a bad example for the point at hand.

      The way I understood the position of the original poster is that C can be faster than every other (higher) language, and that the only reason to choose some language over C is because the source code will be smaller / more maintainable (ie: the impedance mismatch with the problem domain will be lower).

      The point I am trying to make is that, if the chosen language matches a complex problem domain, then the only solution would be to re-implement everything in C and tune it to hell to match the "higher language" implementation.

      Of course, my example were extreme, as they are basically library calls, but we can do some "more realistic" examples (but at the end, everything will boil down to explicit or implicit library calls):

      1) A unification function. Here is some full LISP code for unification (http://web.cecs.pdx.edu/~mperkows/CLASS_ROBOTICS/LISP/tanimoto/UNIFY.CL)

      Here is someone posting some "similar" C code. (http://coding.derkeiler.com/Archive/Prolog/comp.lang.prolog/2006-04/msg00084.html)

      Unfortunately, as said in the post, the C code lacks variable handling which is "for free" in the lisp version. Oops. To get that working, you basically have to implement a chunk of lisp. And if you want your unification routine to outperform the lisp one on every input, you may have to get smart in memory copy (no duplication of nodes during recursion) and smart in memory usage (deleting unneeded node when necessary). This means a garbage collector. Oops again.

      At the end, you'll end up with a full lisp interpreter in your C code.

      2) Software using self-modifying code.

      LISP, SmallTalk, Javascript or even Java, have the possibility of adding code to a running program. If we take JIT versions of LISP or Java, we can build code that evaluate function with a much better performance than any C parser / interpreter, because it will be JITed. The only solution in C would be to use something like LLVM, but I think that using such huge library would be cheating.

      3) A scheme interpreter. This isn't very difficult to write in a LISP dialect, and extremely hard to do in C, for obvious reasons.

      Of course, all those examples will seem weird and contrived to a C coder, precisely because it doesn't match C problem domain. Which was my original point.

    168. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      Indeed - but then this is one of the huge advantages of Functional programming - it's easy to parallelise programs. Come back when you've parallelised the C version. Note, I don't doubt that it's possible, or that it'll be faster than the Haskell version, but you'll have expended a lot of time and effort in the C version for something that was easy in Haskell.

    169. Re:"functional programming languages can beat C" by jbolden · · Score: 1

      What he was saying as far as I can tell is given no concern for programmer time, C is always faster than higher level languages which is basically true at least for mainstream CPUs. Your three examples here are easy to do in LISP but I'm not sure they are faster.

      You seem for some reason to be comfortable letting high level languages use libraries but not C. To keep hammering, C can call the mathematica kerne via. the APIs and get the same or very slightly better performance.

      So for example

      1) C doesn't use this terminology. But just about any function application in any interpreted language is going to be a unification. If it is going to be compiled, you will end up with void function invocations and those are blazing fast in C. That's going to compile down to instruction loader and a memory address (essentially a goto).

      2) c does support self modification. But LISPs are for example written in C. As for a JIT that has a good C, .NET is a fair comparison where you have a bytecode system with a C. And the C is just going to be a bunch of CIL calls so again fast.

      3) Schemes are written in C. That's not a small program anymore.

      Qi did basically the benchmarks you propose. Fairly complex routines written in Qi vs. low level common Lisp. Low level common lisp for 30 line QI program was about 11% faster. If that was worth taking a 1 hour job and converting into a 10 hour job is a big question. C probably would have bought another 20% in exchange for making it a 5000 line program that took 3 weeks.

    170. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      nweb is only 201 lines of code and it's HTTP 1.1 compliant

      Examine the code again. nweb is not HTTP/1.1 compliant. It is not even fully HTTP/1.0 compliant -- check out how it deals with the GET method and how it does error recovery for long reads. Oh for an unwind-protect and/or a dynamically sized input buffer!

      nweb is, however, well documented and reasonably portable C.

      There is no reason whatsoever to expect that nweb would ever be compute bound.

      Compute-boundedness for long or frequent runs is atypical anyway. Attacking all problems with LLLs because they can perform more iops per unit time is simply premature optimization.

    171. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Furthermore, some languages have access to control constructs that C does not. C is limited by its function call convention, which is to push function parameters, call the function, then clean up the stack. Unless a function gets inlined, C must do this every time it moves program control outside the current function. But there are other languages that can call code without doing this.

      For one, aggressive tail-call optimization compiles down to a stack-rewrite plus a goto, rather than consuming the additional time and space needed to push before the call and pop afterward.

      For another, coroutines allow a program to maintain multiple argument stacks, effectively executing gotos between threads of control. There is no easy, portable way to do this in C (although there are a few hideous, stack-rewriting hacks).

      While it's admittedly unlikely, solutions that are particularly efficient due to these techniques might be more efficient than any possible C program.

      But, more to the point, for a given problem there is likely to be a C program that is as efficient as a high-level approach, but it may need to be written in manner so convoluted and atypical that it is effectively unmaintainable, maybe even unwritable by humans. (For example: Is Scheme Faster Than C?)

    172. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      " I've seen a LISP compiler generate better loop code in some cases, simply because it can prove arrays are non-overlapping, or that X*X is provably positive. "

      BS. If the compiler can figure it out, the author can do the optimization as well.

      He can even optimize special cases which the optimizer cannot detect.

    173. Re:"functional programming languages can beat C" by harryandthehenderson · · Score: 1

      That and the fact that many of these languages touted as being faster than C usually have runtime environments that are written in C or C++. How they can be faster than the language their runtime environments are written in is an amusing thing to hear them try to explain away.

    174. Re:"functional programming languages can beat C" by bcrowell · · Score: 1

      people should be shedding the ideas that functional languages are slow, and unusable, and trying them out in industry

      There are some practical things that may make it difficult for that to happen.

      I learned some Haskell recently, and the impression I got was that it was a lot like TeX, in the sense that there's a core language that's really a beautiful work of art, but slathered on top of that you get layer after layer of add-on software that is a mixed bag in terms of quality. I found a lot of issues with poor support for regexes and unicode strings, for example. The fact that Haskell has two different implementations of strings does sort of seem to me like an admission that if you do strings in the most elegant possible fp way (as lists of characters, manipulated using pattern matching), it may indeed be "slow and unusable."

      With LISP, lack of standardization is an issue.

      As you've noted, automagical support for parallelization is a huge factor in favor of fp now that hardware is moving toward SMP. But, e.g., ocaml's implementation of gc prevents it from doing parallelization as well as erlang.

      As with any language that has a small population of users, fp languages often have issues with poor documentation, or lack of native libraries, or of conveniently packaged bindings to non-native libraries.

      The thing is, there are a lot of nice multi-paradigm languages to choose from that are very well implemented, have excellent libraries, excellent documentation -- and that also allow you to use fp techniques for tasks that naturally lend themselves to fp. You can do fp in ruby or perl, for example.

    175. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 2, Insightful

      I find your whole comment rather odd. You're essentially saying "it's not fair, the Haskell compiler optimises code better than the C compiler does". The Haskell compiler has recognised that the task it's being asked to do does not require everything to be evaluated, and hence is optimising that code away.

      The bottom line is if you're asked "produce this output", and you do so then it's entirely valid. The fact that Haskell is amenable to massive optimisation like that is something the shootout should be demonstrating.

      *sigh*

      I'm not saying the test is "unfair". I'm merely saying that it is incorrect.

      If the point of the test is to determine actual performance of e.g. sorting algorithm, then the test should at least make sure that the output of sorting is used (e.g. displayed)! It doesn't matter how the compiler does the sorting - let it optimize it the best way it can - but it should be forced to produce the complete sorted sequence either way. Otherwise you aren't really measuring sorting... you're measuring how well the compiler can detect and remove dead code, and the test is meaningless for its original goal. Because when you write an real-world application in Haskell that does use the output of the algorithm, then you'll hit the actual performance figures, and not the imaginary ones from the Shootout.

      Let me put it that way. Let's say I design a language with all the usual operators (imperative, for simplicity sake), Turing-complete, but no output facilities - the only thing it can output is the time it took to run the program. I then write a compiler for it, which - since there's no way to output information - just discards all computations, and prints "0 milliseconds" to the output. I then claim that this language clearly beats any other language in the Shootout on any test. Which it completely factually correct, if the test output consists only of time it took to run it - but how useful would such a language be to you in practice?

      And to fire back at the "unfairness" of the shootout, Haskell has been banned from putting a pragma in some of its programs that specifies how the garbage collector should behave. Why? Because when that's done, the code runs 4 times faster, and beats C.

      I wonder what the pragma is - cannot find anything in Google. Is it something that basically results in it not freeing memory at all for the duration of the test, and letting the system do it when the process shuts down?

    176. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 1

      Sounds like an imperative programmer talking: you 'use' the sort. As if it is a certain step in a program, instead of something that can be interleaved with other calculations.

      You're very wrong. An imperative programmer "invokes" or "runs" the sort. A functional programmer "uses" its result in another computation. The latter is entirely consistent with FP paradigm.

      On a side note, if you're doing a sort but not using its output - regardless of lazyness/eagerness of the language - then why you're doing it in the first place? In pure FP language such as Haskell it's even more visible, since you essentially forcibly ignore the result of a function you call, and there are no side-effects - so you very clearly tell the compiler to "do nothing". And why would you explicitly write "do nothing" in your program (unless you're coding in Nil)? But it is exactly what the Shootout guys did.

      As a related anecdote, the IOCCC guys have once got a technical winner - the shortest C program possible that produced itself as its output. It was a blank .c file (and a makefile that just renamed and chmod+x it so it becomes a do-nothing binary). It was a valid entry by the existing rules... but it forced the rule change afterwards, and for a good reason.

    177. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      That and the fact that many of these languages touted as being faster than C usually have runtime environments that are written in C or C++. How they can be faster than the language their runtime environments are written in is an amusing thing to hear them try to explain away.

      This is right on target.

      John Fremlin's blog, linked from the article, starts off today with praise for the performance of Pico Lisp. So I downloaded the source for Pico Lisp, and guess what? It's written in C! I swear, this article has to be a joke.

    178. Re:"functional programming languages can beat C" by Hercynium · · Score: 2, Informative

      Maybe this is overly pedantic, but I've seen it mentioned several times in various posts that "Orbitz is powered by LISP"

      That's very true, but only one component of their back-end is actually written in LISP - the lowest-fare search engine.

      Also, Orbitz did not write that component, called QPX - it was actually written by a company called ITA Software, who licenses it to dozens of other air-fare cross-shopping services.

      Despite the other issues with Orbitz, QPX is an excellent example of what can be accomplished by highly skilled LISP programmers - an exceedingly fast, flexible, and successful search algorithm that they have been able to maintain as the industry leader since it's invention over twelve years ago.

      As far as your assessment of "Orbitz is ridiculously slow for the amount of data it processes" I beg to differ. Having worked for ITA in the past, let me tell you the amount of data searched through is staggering, especially when you consider that that data set is updated continuously, in nearly-real-time (I could claim real-time, but I like being accurate)

      Combine that data source with the fact that the queries sent can have dozens (and in some cases hundreds) of parameters, and various results can be filtered and modified arbitrarily based on rules imposed by the airlines and their sales partners (eg. Orbitz' negotiated fares for Airline X vs Airline Y, per flight/date/time/passengers/booking class etc etc etc) *and* that without a highly sophisticated approach to finding the best solutions the result set can have *billions* of possibilities....

      Yeah... Orbitz' fare searching is pretty damned fast, considering.

      --
      I'm done with sigs. Sigs are lame.
    179. Re:"functional programming languages can beat C" by Hercynium · · Score: 1

      Perl became popular because it is very good at what it was designed to do - munging text with incredible flexibility and impressive speed - and it was the best available tool for the job when that ability was in high demand: the birth of the web.

      Now, you can argue syntax ugliness all you want, I consider that subjective. However, when you begin to truly grok all of Perl's abilities, it's hard *not* to appreciate a fundamental beauty to the language.

      I dare say, would you declare the German language a "monstrosity" because to American ears Deutsche has too many harsh-sounding words? Tell that to a German and he'll gladly smack you upside the head with a book of Goethe's poetry or perhaps the works of Wagner or Strauss!

      Go read "Higher Order Perl" by Mark Jason Dominus and learn how to leverage Perl's features using the same techniques that LISP and ML programmers take for granted...

      As a native speaker of Perl, I actually consider sigils and braces quite natural and beautiful.

      --
      I'm done with sigs. Sigs are lame.
    180. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Alright, the small challenge is... Eclipse.
      Now get to work!

    181. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      I'm not saying the test is "unfair". I'm merely saying that it is incorrect.
      Oh, then your point is irrelevant, the challenge was "can you show me a functional program that I can't write faster in C"... The debian language shootouts has a few examples of functional programs that people have tried to write faster in C, but not yet succeeded, so that's a good starting point.

      At the end of the day, the debian language shootout is all just a bit of intelectual fun and penis size comparing, but it's still a valid place to draw code from in this case.

      If the point of the test is to determine actual performance of e.g. sorting algorithm
      But no one said that was the point of the test, so any solution that meets the requirements set out is entirely valid.

      I then claim that this language clearly beats any other language in the Shootout on any test.
      Absolutely, entirely valid. And in fact that's an interesting result - if the language is amenable to that kind of analysis, then great, that's a real advantage of the language. Of course, it would be nice if our benchmark suite tested a little more than that, but still it's a very valid and useful result.

      I wonder what the pragma is
      {-# OPTIONS -A300M #-} as a comment at the beginning of the file, and no, it's something that says "at some point, you will definitely need 300MB resident at the same time, tune your GC accordingly".

    182. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      As a final note â" a C program that did no cleanup after itself and let the OS free up the RAM would be considered valid, so even if the pragma were to do that, what's the problem?

    183. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Some compilers may do a better job emitting native object code than they do targeting an intermediate representation of any type (LLVM IR, macro assembly, C), and will routinely outperform C regenerated from one of these intermediate representations largely because of proximity to the underlying ISA.

      This is particularly true if an idiosyncratic calling convention is used for functions that are guaranteed to be called only by code generated by that compiler (this does not exclude a suitable trampoline however).

      You could think of this as a sort of "nonlocal partial inlining", for example, or as a way of making more use of scarce register resources or better use of the top of the stack.

      Things like this may not survive passage through an intermediate representation, particularly when one cannot make guarantees about callers.

      Hoisting lots of error and safety checking into the compile phase is also something easier done when the target is machine code than an IR.

      On the other hand, this does not preclude IRs that are tuned for the path from HLL to object code; several simplifications of C have used this way by a number of compiler designers (C-- springs immediately to mind).

      So it does not follow that mechanically translating HLL to C and then using a good (or even great) C compiler to produce object code will necessarily perform even as well as HLL directly to object code.

    184. Re:"functional programming languages can beat C" by TheRaven64 · · Score: 1

      This is particularly true if an idiosyncratic calling convention is used for functions that are guaranteed to be called only by code generated by that compiler

      LLVM will use more efficient, non-standard, calling conventions for functions that are not called externally. It will also generate specialised versions of the function based on the inputs.

      If you'd mentioned a language like PL/M, then you might have a point, but only because PL/M is a lower-level language than C.

      --
      I am TheRaven on Soylent News
    185. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 1

      As a final note - a C program that did no cleanup after itself and let the OS free up the RAM would be considered valid, so even if the pragma were to do that, what's the problem?

      No problem really - you might actually want to do just that in some real world scenarios; e.g. I heard that Unreal Engine circa 2004 used GC, but only ran the cycle between map changes - but was the C program in the Shootout written that way? In other words, if you use this optimization for both C and Haskell, is the latter still 4x faster?

    186. Re:"functional programming languages can beat C" by 32771 · · Score: 1

      Hard to say, the start of fort.10 (od -t x8 fort.10|less)
      looks like the following:

      0000000 0000000000028000 00000000fff80000
      0000020 0000000000000000 00000000fff80000
      *
      0237760 0000000000000000 0000000000000000
      0240000 d1432f7a00000000 000000003fc66b82

      I compiled with:
      gfortran-4.3 -O3 -march=core2 -mfpmath=sse test.f  -o test_slashdot

      Also I found out that sqrt(-x)=i*sqrt(x).  You would only have to calculate a subset of the 100x10240 data points, does the compiler do that? It doesn't seem so.
      I'm wondering whether C++ does this sort of thing too, it supposedly has a complex data type.
      It does have a complex data type but also uses a function call:
      ...
          cvtsi2sd    -164164(%ebp), %xmm0
          leal    -246012(%ebp), %ebx
          movsd    %xmm0, -164160(%ebp)
          movl    $-5119, %edi
          movsd    mpi, %xmm0
          movsd    %xmm0, -164176(%ebp)
          .p2align 4,,10
          .p2align 3
      .L6:
          cvtsi2sd    %edi, %xmm0
          leal    -164144(%ebp), %eax
          mulsd    -164176(%ebp), %xmm0
          incl    %edi
          mulsd    -164160(%ebp), %xmm0
          movl    $0, 12(%esp)
          movsd    %xmm0, 4(%esp)
          movl    $0, 16(%esp)
          movl    %eax, (%esp)
          call    csqrt                        ;that wasn't necessary
          movsd    -164144(%ebp), %xmm1
          movsd    -164136(%ebp), %xmm0
          subl    $4, %esp
          movsd    %xmm0, (%ebx)
          movsd    %xmm1, -8(%ebx)
          addl    $16, %ebx
          cmpl    $5121, %edi
          jne    .L6
      ...
      Here is the code:
      #include <iostream>
      #include <complex>
      #include <cmath>
      using namespace std;
      double mpi=3.141592653589793238462/1.024;
      int main(void){
        int i,j;
        for(j=10;j<=110;j++){
          complex<double>  r[10240];
          for(i=-5119;i<=5120;i++){
            complex<double> in(mpi*i*j,0);
            r[i]=sqrt(in);
          }
          for(i=-5119;i<=5120;i++) cout << r[i] <<endl;
        }
        return 0;
      }
      Here is a part of the output around i=0 :
      ...
      (0,9.59369)
      (0,7.83321)
      (0,5.53892)
      (0,0)
      (5.53892,0)
      (7.83321,0)
      (9.59369,0)
      ...
      I compiled with:
      g++ -O3 -mfpmath=sse -march=core2 test_slashdot.c  -o test_slashdot3 -lm

      So I would say that Fortran has the chance of better understanding what you
      want of it but it only goes half way because like C++ it doesn't recognize the repeated operations.
      You could set out and do it all by hand in C and get a better performance, but if you want to spend equal effort Fortran looks pretty good.
      I have this suspicion, that the floating point nature of the data causes the compiler to throw out the possibility of just moving the positive sqrt into the imaginary part of r, but my tests couldn't find any appropriate optimization settings.

      --
      Je me souviens.
    187. Re:"functional programming languages can beat C" by artagnon · · Score: 1

      I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C. I leave this challenge out to anyone to take.

      Your point being? My implementation in x86 assembly will be faster than your C code. So what are you trying to say here? That the processor only accepts a certain instruction set and that it doesn't understand Python or LISP or C? Isn't that glaringly obvious? All your code is finally converted back to assembly, and speed of execution depends upon how much the compiler can assume. If the compiler knows how big a certain variable is, it'll allocate exactly that much memory for it. If it doesn't, it'll have to take some extra precautions, which'll ultimately make the equivalent assembly slower. The more information you provide to the compiler about how the processor will execute the program, the more optimized your code will be. It's as simple as that.

      C is approximately the equivalent of "portable assembly code", so nobody is surprised. Assembly allows you to control individual registers on the CPU, C has slightly higher data types which ultimately map to registers and HLLs have abstract data types. The objective of a HLL is to minimize programmer time, while making sure that the computer execution time doesn't suffer too much.

      A smart programmer wouldn't write everything in assembly and C. That is too painful. Instead, he'd write everything in a HLL, profile it and find the bottlenecks. Then he would make the code that's causing the program to bottleneck more explicit (closer to the processor). Ofcourse, there are some projects that are so CPU-intensive that every line of code is practically a bottleneck, and they have to be written in C and assembly. FFmpeg for example.

    188. Re:"functional programming languages can beat C" by MrMr · · Score: 1

      I had to change the array index i to i+5119. But then it works. I will replace the cout with a binary write and play around a bit.

    189. Re:"functional programming languages can beat C" by beelsebob · · Score: 1

      The 4 times faster was in reference to the Haskell code â" simply applying this one pragma sped it up 4 times. On the quad core machine, it sped it up 16 times - which exposes one of the major weaknesses of ghc's implementation just now: the GC system blocks all other threads, so the Haskell program sees no multi-core speedup, because all the time is spent blocked waiting for the garbage collector to discover it really does need to allocate more ram.

    190. Re:"functional programming languages can beat C" by metamatic · · Score: 1

      TCL takes the same principle even further, and it's nowhere near as popular or admired.

      That merely means that having metaprogramming is not a sufficient condition to make a language admired; it doesn't mean that having metaprogramming is not a necessary condition to make a language admired.

      Or to put it less technically: TCL isn't admired for reasons which have nothing to do with presence or absence of metaprogramming.

      Or to provide an example which has the same structure as your argument, and hopefully shows up its defectiveness: "Support for multiple data types is required for a language to be comparable to Lisp." "Yeah, well, PHP has multiple data types and it sucks."

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    191. Re:"functional programming languages can beat C" by ratboy666 · · Score: 1

      Of course you can

      VM based systems are free to recompile and optimize code at run-time.

      C compilers? Not so much. Unless... The compiled C code can recompile and optimize at run-time as well. The Helium Flame project at HP was one such an effort.

      But the C language is just not expressive enough. Some things that could be exploited just won't be. Others -- well, run-time information may give clues. As an example:

      if (condition) {
          code1...
      } else {
          code2...
      }

      The COMPILER has no clue as to which branch is important. Say, code2 is a branch which is NEVER TAKEN (its an obscure error report). There is no construct in C that allows this to be specified (well, SUN has #pragma rarely_used).

      You say, so what? Branch prediction takes care of it. But that isn't the whole story -- code2 is actually rather small (say: fprintf(stderr, "error: bad return"); exit(1);) It overlaps the cacheline with code1, and forces a cache line reload. The Laws of Thermodynamics. Energy will be expended loading the code, simply to ignore it.

      Wouldn't it be better to MOVE code2, along with all the other snippets that aren't used into a demand load page that is simply not loaded? This requires either 1) more expressiveness in C, or 2) some really smart run-time optimizations.

      VM based systems can apply those optimizations, and can support higher level constructs, resulting in even more optimization opportunities. Of course, we live in a "C-centric" world; even processors that COULD do better don't, simply because C won't support it (witness the tuning of instructions in the x86 world).

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    192. Re:"functional programming languages can beat C" by Vellmont · · Score: 1


      I mean, that monstrosity of a language - Perl actually became popular. If that doesn't prove that popularity doesn't prove goodness, I don't know what does.

      I'm not a perl programmer, and I dislike the language quite a bit. But.. over the years I've definitely seen that it simply must have some intrinsic value, especially with regard to text processing as so much useful code exists for this very purpose.

      I guess my point is that "goodness" is a product of its environment. If you're doing text processing and largely only text processing, perl is "goodness". If you're doing programming where code size is a concern (but not a MAJOR concern, i.e. you have a few kilobytes) then C is "goodness". If you're doing business programming with lots of business logic on the server side, Java becomes "goodness".

      I'd even go so far as to say that the value of a language, stripped away from the domain of what the problem is, is meaningless. I don't think a language has intrinsic merit, since there's always a job to be done (and thus a problem domain).

      --
      AccountKiller
    193. Re:"functional programming languages can beat C" by 32771 · · Score: 1

      Oddly enough the array index bug didn't cause any trouble on my side. Here is my attempt in C where I try to do the thinking for the compiler:

      #include <stdio.h>
      #include <math.h>
      double mpi=3.141592653589793238462/1.024;
      int main(void){
        int i,j;
        double r_re[10240];
        double r_im[10240];
        for(j=10;j<=110;j++){
          for(i=0;i<5119;i++){
            double rt=sqrt(mpi*(5119-i)*j);
            r_im[i]=rt;
            r_re[i]=0.0;

            r_re[5119+5119-i]=rt;
            r_im[5119+5119-i]=0.0;
          }
          r_im[5119]=0.0;
          r_re[5119]=0.0;
          r_im[10239]=0.0;
          r_re[10239]=sqrt(mpi*5120*j);
          for(i=-5119;i<=5120;i++)
            printf("(%f, %f)\n", r_re[i+5119], r_im[i+5119]);
        }
        return 0;
      }

      Using unsafe math will get rid of the function calls to sqrt the compiler will still be making otherwise.
      The above code is a decent trade off between not expending too much effort and getting reasonable performance I think. I have some more ideas but they won't make the thing any easier to understand and program.

      Squeaky clean, eh?
      ...
      .L2:
              cvtsi2sd        -163860(%ebp), %xmm1
              xorl    %edx, %edx
              mulsd   mpi, %xmm1
              movl    $5119, %eax
              .p2align 4,,10
              .p2align 3
      .L3:
              cvtsi2sd        %eax, %xmm0
              movl    $0, (%esi,%edx,8)
              movl    $0, 4(%esi,%edx,8)
              mulsd   %xmm1, %xmm0
              sqrtsd  %xmm0, %xmm0
              movsd   %xmm0, (%edi,%edx,8)
              movsd   %xmm0, 40952(%esi,%eax,8)
              movl    $0, 40952(%edi,%eax,8)
              movl    $0, 40956(%edi,%eax,8)
              incl    %edx
              decl    %eax
              cmpl    $5119, %edx
              jne     .L3
              mulsd   .LC1, %xmm1
              movl    $0, -122904(%ebp)
              sqrtsd  %xmm1, %xmm0
              movl    $0, -122900(%ebp)
              movl    $0, -40984(%ebp)
              movl    $0, -40980(%ebp)
              movl    $0, -81944(%ebp)
              movl    $0, -81940(%ebp)
              movsd   %xmm0, -24(%ebp)
      ...
      With:
      gcc -O3 -mfpmath=sse -march=core2 -funsafe-loop-optimizations -ffast-math -funsafe-math-optimizations -fassociative-math -freciprocal-math test_slashdot.c -S -o test_slashdot4.s -lm

      (former Gentoo user at play)

      --
      Je me souviens.
    194. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      >> I mean, that monstrosity of a language - Perl actually became popular. If that doesn't prove that popularity doesn't prove goodness, I don't know what does.
      > I guess my point is that "goodness" is a product of its environment. If you're doing text processing and largely only text processing, perl is "goodness".

      You know, here in the non-geek world, we have a word for "goodness," it's called quality.

    195. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      Lisp fans always claim this, but I think it's a red herring.

      It's not a red herring, it's just too difficult for any of the people who crow about it to actually do. The testing tool Heckle gets great mileage out of this quality in Ruby, and I'm doing my best to reproduce it in Erlang.

      TCL takes the same principle even further, and it's nowhere near as popular or admired.

      That's because TCL is agonizing.

      --
      StoneCypher is Full of BS
    196. Re:"functional programming languages can beat C" by stonecypher · · Score: 0, Troll

      Despite the other issues with Orbitz, QPX is an excellent example of what can be accomplished by highly skilled LISP programmers - an exceedingly fast, flexible, and successful search algorithm that they have been able to maintain as the industry leader since it's invention over twelve years ago.

      You seem to have missed the point entirely. Nobody said LISP wasn't powerful enough to express complex algorithms. (I'd be interested to learn what industry you think is being led by ITA, though; the Orbitz engine would be lightning fast using simple iterated A* and a creative distance metric.)

      As far as your assessment of "Orbitz is ridiculously slow for the amount of data it processes" I beg to differ. Having worked for ITA in the past, let me tell you the amount of data searched through is staggering, especially when you consider that that data set is updated continuously, in nearly-real-time (I could claim real-time, but I like being accurate)

      It shouldn't be. Fares just aren't that complex. It's a straightforward directed graph. Your fare search should be several orders of magnitude cheaper than Google Maps' generating a driving path from Boston to Los Angeles, yet Google Maps is done in under a second and Orbitz typically takes 20+ seconds.

      If you used to work for ITA, contact me in private and help me understand algorithm context. I used to write Gameboy Color games; you don't know anyone who squeezes speed like I do. There may be a profitable contracting endeavour which we could split 50/50.

      Let's be clear: if you have ten thousand airline vendors offering each one hundred thousand flights per day, most staggered across gates, and you need to satisfy group constraints like having N minutes between connections so that someone can travel between terminals, and you have seating constraints and time constraints, and on top of that you have to make fare and time balanced searches - and that's way, way more data than an orbitz fare search should need - you should still be clocking in around one tenth of a second of cpu time.

      I'm going to say it again: I have set upper bounds that are unrealistic given the real world commercial environment (there's no way there are that many airlines making that many flights), and I still openly reject the claim that the processing time here is in any way reasonable.

      Talk to me. If you can set up contact and communicate the problem constraints to me, we can package benchmarks of a replacement with that Google paper about one second delay causing 40% traffic loss, and make ourselves a nice little pile of money.

      My blog has my email address.

      --
      StoneCypher is Full of BS
    197. Re:"functional programming languages can beat C" by ratboy666 · · Score: 1

      Yes, quite a few of these systems target C -- using it as a sort of assembler. This doesn't mean that the generated C is anything a human would have written. For example, in my answer to this "challenge" I used the factorial function. Part of the (temporary) C code generated by the scheme compiler looks like this:

      ___BEGIN_P_COD
      ___BEGIN_P_HLBL
      ___DEF_P_HLBL_INTRO
      ___DEF_P_HLBL(___L0__20_x_2e_o3)
      ___END_P_HLBL
      ___BEGIN_P_SW
      ___DEF_SLBL(0,___L0__20_x_2e_o3)
            ___IF_NARGS_EQ(0,___NOTHING)
            ___WRONG_NARGS(0,0,0,0)
      ___DEF_GLBL(___L__20_x_2e_o3)
            ___SET_GLO(1,___G_factorial,___PRC(3))
            ___SET_R1(___VOID)
            ___JUMPPRM(___NOTHING,___R0)
      ___END_P_SW
      ___END_P_COD

      Not something a human would code at all. Indeed, these systems are used to stress-test the C compiler, resulting in improvements there.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    198. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Yes, at significantly more trouble. Did you know that a static type deduction is equivalent to a constructive proof quantifying over sets and functions? That means that a language with a Turing complete static-type deduction system can go ahead and prove things at compile-time, automatically.

      C's only comparable functionality is with the use of macros.

    199. Re:"functional programming languages can beat C" by aevans · · Score: 0

      TCL is still way more popular than every variety of Lisp combined.

    200. Re:"functional programming languages can beat C" by skeeto · · Score: 1

      Here's one for you. This guy implemented the Sieve of Eratosthenes in Ocaml and in C as best he could and found that the Ocaml version is faster.

      http://groups.google.com/group/comp.ai.genetic/msg/0e6338ae12f1f653?pli=1

      Could you write it in C so that it's faster?

    201. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 1, Informative

      When Google Maps chooses a route, the length of road A doesn't change depending on whether or not you will be coming back via road B on a weeknight. Airlines use such elaborate and constantly changing rules to create price discrimination that two people on the same flight almost never pay the same fare.

    202. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      Right, so everything that wins is clearly the best thing. I guess you wrote this post from IE on a windows 7 box right? Using anything else would be stupid since they didn't win. It is a free market after all.

      >It's a little like SICP. If it's been that free, that well known and that easily accessable for 20 years, how come it's
      >being discarded by the university that published it for curriculum, and how come its design principles are largely
      >unseen even in the work of people who have read it?"

      No need to wonder, it was explained why it was ditched. Basically "because programming today isn't about knowing how to write code, but rather how to use libraries". In other words, not because it was inferior but because "programmers" are now to be trained how to use existing systems, not to make new ones.

      >But don't kid yourself. They died for a reason. Why is it that all the supposedly awful languages and design
      >strategies are dominant?

      This is also pretty simple: politics.

      >It's because they work. For all their warts, for all their maintenance problems, for all the infrastructure you have to >write, they work.

      Very nearly a tautology. Anything "works" if you put enough effort into it. People tend to over complicate things to the point that they feel they need to write lots and lots of code to accomplish simple tasks. Just look at virtually any Java project.

      >Trade that for real exceptions and a strong type system, and you've chosen C++.

      Epic fail. LISP has a vastly superior "exception" system then C++. C++'s is just good for postmortem, if you want to make a self-recovery you're going to have to write a lot of code since exceptions are never resumable.

      I'm pretty surprised to see you know enough about Haskell to know that it is concise, but then turn around and call C++, one of the worst examples of a "strong type system" ever a "strong type system".

      >Typically the LISPer who talks about how superior LISP is doesn't know many (or any) other exotic languages;

      Do you actually know any LISPers? The only ones I know know *only* exotic languages (e.g. they probably wont know garbage like C++, but Haskell or Erlang is likely).

      >Even C++ offers nearly everything that LISP does at this point

      Are you comparing C++ to newLisp? Because at this point I have to wonder if you actually know the language at all.

      >which aren't anywhere near as powerful as C++'s algorithm and container library IMO

      So some libraries C++ has are more powerful than *Lisp's facility for writing libraries*? That whole sentence was just completely retarded.

      You might have had a comparison had you (known enough to?) compared Lisp macros with C++'s templates. But that's dangerous because it leads to comparisons of the hoops you have to jump through to do something non-trivial in C++'s template syntax vs. a straight forward Lisp macro. And of course C++'s templates are completely isolated to compile time. You couldn't define a normal C++ function and use it in a template to determine something at compile time.

      Not to mention all that hoop jumping for C++ templates is just to make your life easier in dealing with C++'s awful type system. So you can make this comparison if you wish, but it's by no means in your favor.

      When your posts started out I thought you might have some insight. But this post has exposed you as a disgruntled C++ and/or PHP programmer tired of people dismissing you as mediocre when you know a "most popular" language.

    203. Re:"functional programming languages can beat C" by Hurricane78 · · Score: 1

      And I am sick of people acting as if it were somehow better to work on the lowest of all levels!

      I don't mean levels of inner platforms. I mean levels of abstraction. For programming efficiency. To make more sense.

      That in these days, people who write normal applications still mess around with basic and long-solved stuff like memory management, garbage collection, and variables/pointers, when they should write the application logic only, and be done in a fraction of the time, while guaranteeing stability and security, is just retarded.

      Maybe you had more time, if you would use a modern language!

      My language of choice: Haskell. Because it just makes fuckin' SENSE for once! (I chose that language, because I was in the process of developing the [for me] perfect language, when I noticed, that Haskell did it all exactly that way, but even better. Haskell is how I think, and always thought about programs.)

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    204. Re:"functional programming languages can beat C" by Ikari+Gendo · · Score: 2, Informative
      Paul Graham has commentary from an ITA insider.

      6. If you want to do a simple round-trip from BOS to LAX in two weeks, coming back in three, willing to entertain a 24 hour departure window for both parts, then limiting to "reasonable" routes (at most 3 flights and at most 10 hours or so) you have about 5,000 ways to get there and 5,000 ways to get back. Listing them is a mostly trivial graph-search (there are a few minor complications, but not many), that anybody could do in a fraction of a second.

      7. The real challenge is that a single fixed itinerary (a fixed set of flights from BOS to LAX and a fixed set back) with only two flights in each direction may have more than 10,000 possible combinations of applicable "fares", each fare with complex restrictions that must be checked against the flights and the other fares. That means that the search space for this simple trip is of the order 5000 x 5000 x 10000, and a naive program would need to do a _lot_ of computation just to validate each of these possibilities. Suitably formalized, its not even clear that the problem of finding the cheapest flight is NP-complete, since it is difficult to put a bound on the size of the solution that will result in the cheapest price. If you're willing to dispense with restrictions on the energy in the universe, then it is actually possible to formalize the cheapest-price problem in a not-too-unreasonable way that leads to a proof of undecidability by reduction to the Post correspondance problem :-).

      So it seems that your assumption that "Fares just aren't that complex. It's a straightforward directed graph." is in error. Remember that this work used to require dedicated intelligence (i.e. a travel agent) who was at a serious disadvantage in terms of fare data.

    205. Re:"functional programming languages can beat C" by Hercynium · · Score: 1

      True, I ignored the original point - generally C|C++ is going to be faster than LISP, if the algorithms necessary can be expressed in similar terms in each language. However, when it comes to having to constantly change the code to support constantly changing requirements, a dynamic language like LISP has a great advantage over C++.

      That said, the code doing the searching for Orbitz uses algorithms and architectural techniques that would take so much more "scaffolding" in C++ that it would not only hamper maintenance of the code, it would likely hamper innovation and invention of new algorithms and functionality.

      LISP is certainly not popular, and in many cases, not the best or most practical tool for the job... but it is alive and well, and will continue to be available to those who can/need to use it for the foreseeable future.

      --
      I'm done with sigs. Sigs are lame.
    206. Re:"functional programming languages can beat C" by Hercynium · · Score: 1

      exactly.

      And the specs Carl cites in that article has grown by an order of magnitude - in both amounts of data and hardware power, as well as the complexity of the requirements.

      --
      I'm done with sigs. Sigs are lame.
    207. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      If all you care is first-class function and functional programming flow, Haskell is the perfect language. Heck, even C provides all of these features (yeah, and it is a hundred times more elegant than Python).

      LISP is all about metaprogramming. From the language (list as syntax) to the library (eval). Next time, before spilling out anything, learn, please.

    208. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      You really know how to make yourself look the fool, don't you?

    209. Re:"functional programming languages can beat C" by setagllib · · Score: 1

      I really don't think it'd be "every other Wednesday". If your code has a genuine problem with aliasing, that is a bug, and for the most part a deterministic one. You can easily confirm the problem by turning off optimisation, for example. It shouldn't even have passed unit tests.

      Besides, what do you propose as an alternative? Fortran, lacking real pointers? Anything safer is slower, and anything faster is too restricted to be a general programming language. C and C++ are an almost unique sweet spot in the programming language universe, for good reasons.

      --
      Sam ty sig.
    210. Re:"functional programming languages can beat C" by ta+bu+shi+da+yu · · Score: 1

      Oh come on, Perl really isn't that bad for what it does! Sheesh.

      --
      XML is like violence. If it doesn't solve the problem, use more.
    211. Re:"functional programming languages can beat C" by Anonymous Coward · · Score: 0

      > And I am sick of people acting as if it were somehow better to work on the lowest of all levels!

      Exactly - it's not really about "low-level" vs. "high-level," it's about speed.

      Speed of development and testing are hugely important since more time is typically spent testing and debugging an application than writing the code in the first place.

      Readability, clarity, and maintainability are important as well, but if you're just going to argue about raw executable performance, it's silly to talk about one language being "faster" than another, since it all depends on the compiler or interpreter.

      Even with C, we used to have endless debates about whether Turbo C (which compiled very fast!) produced slower code than Microsoft C.

    212. Re:"functional programming languages can beat C" by berend+botje · · Score: 1

      So basically you're saying that assembler is faster than C? Or am I missing your point?

    213. Re:"functional programming languages can beat C" by Gorobei · · Score: 1

      Well, hard to catch with unittests, because correct tests will pass, but incorrects may also pass. All unit tests may happily pass, yet the final application may fail because of an interaction of aliased pointers: which "unit" would be able to catch this?

      Alternatives naturally depend upon the application itself, the domain, the skill level of the programmers, etc. My current app (100+ developers, 10M LOC) has stateless C/C++ routines for the heavy number crunching (heavily optimized with serious unittests,) the next layer interfaces to those using a high-level functional language (no side-effects, so many programmers can work on a system without hosing each other down,) and then high-level stuff to schedule work out to multi-thousand CPU compute farms in a reasonable manner, finally little apps sit on top of that (most are just a few lines of code of the form "please compute X".) Works for my domain, but probably not for most.

    214. Re:"functional programming languages can beat C" by SnowZero · · Score: 1

      Um, I did try using it widely in my inner loops[1], and as I stated above: I have never found "restrict" to help at all. Type aliasing was made out to be this huge issue when people talked about languages and compilers, but when C99 and GCC fixed that, it turned out not to be much of a practical issue at all[2].

      So, AFAICT, C/C++ programmers should not bother with restrict except as performance experiments on very critical code, where it is worth trying lots of techniques in case they help. I'm glad we seem to agree on that :)

      [1] There is no point to optimizing outside of core loops in most programs. The programmer should spend their optimization work where it matters most.
      [2] YMMV, as I'm just stating my experience. I also mentioned this in GP.

    215. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      No, I'm saying they are functionally equivalent. So, the comparison is bogus. There are other ways to prove this, but this one is the most obvious and straight through sea.

      --
      This is a replacement signature.
    216. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      Yes, I understand your concern with my argument. You, however, misunderstand my argument. I'm trying to point here to the functional equivalency of these two language paradigms and the added ability of functional languages to generate larger, long-term structures which can prevail, since direct optimalization has not yet taken place. This in turn allows for a faster product cycle, thus generating higher return of investment. There are other elements which are profitable, such as the advantage of simpler serialization and parallelization of code. And, for me the most important argument against an imperative design is the ability to generate abstract language structures in a functional language. If you want, I can explain this further.

      However, many arguments are maintainable against functional languages. The most important one is the difficulty in understanding time and space complexity in this group. Often, the compiler might optimize, with unexpected results (mostly when it doesn't though). So, don't get me wrong, I don't want to promote functional languages above iterative ones, I just want to show their specific aspects: equivalent to iterative languages, highly abstractable, unexpected optimizations.

      Btw., I'm sorry for this late reply, I hope you'll take the time to read it and reply!

      --
      This is a replacement signature.
    217. Re:"functional programming languages can beat C" by phantomfive · · Score: 1

      There was a time when I really worried about which programming language was better for writing code. Since then, I've realized that it doesn't really matter all that much, as long as you can encapsulate your functional pieces of code into pieces that can be reused flexibly. Thus while object oriented languages save a little bit of typing ( you can write object.functionCall() instead of functionCall(object)), their major advantage is that they encourage you to divide your code into flexible, reusable chunks. But once you've learned how to do this, you no longer need this encouragement, and it matters a lot less what language you use.

      In short, with the right libraries, I can write something in C as quickly as I can in Perl, because I've learned how to organize my code correctly. Someone said, "a language that doesn't teach you more about programming isn't worth learning." And that is the advantage of functional programming languages, they teach you something new. They improve your programming vocabulary.

      --
      Qxe4
    218. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      I agree absolutely with flexible code-reuse and the programming language independence of this element. However, to say that OOP saves 'a little typing' is a gross understatement in my opinion. OOPs type morphology is the more flexible one. As the earliest C++ macros show, it is perfectly possible to implement this in C, but not very welcome, as we'd all have different standards.

      The case for functional languages is similar: although a good design allows a functional approach in an iterative language, and vice versa, the major difference is uniformity of language and run-time code manipulation, plus a more 'involved' interpretter/compiler, as lambda reductions and optimalizations are somewhat more complicated than simple compiling in an iterative language.

      --
      This is a replacement signature.
    219. Re:"functional programming languages can beat C" by mauddib~ · · Score: 1

      How to begin the argument, lets see...

      1. The result of a compound function, such as f(g(a)), with f and g being functions, and 'a' an argument is not always of complexity O(g(a)) + O(f(a)), it can be much lower.

      2. An imperitive language can make 'some' optimizations, but since the language itself cannot optimize further at run-time, compound functions are often a bottleneck and require programming effort and parallel programming effort.

      3. A functional language might (or might not) see the possibilities of lambda reductions and give automatic optimization of these compound functions.

      4. Therefor, 'using' a sort function sounds rather odd. The word 'apply' sounds much better. You apply the lambda expression on the inner expression, thus allowing certain reductions.

      --
      This is a replacement signature.
    220. Re:"functional programming languages can beat C" by shutdown+-p+now · · Score: 1

      Therefor, 'using' a sort function sounds rather odd. The word 'apply' sounds much better. You apply the lambda expression on the inner expression, thus allowing certain reductions.

      Agreed, "apply" is the most precise term here. But the result of that application is then "used" (or not used, as was the case for the Shootout) in another application.

      An imperitive language can make 'some' optimizations, but since the language itself cannot optimize further at run-time, compound functions are often a bottleneck and require programming effort and parallel programming effort.

      First of all, of course a compiler for any language (including imperative) can optimize at run-time, if it's targeting a VM (see: Java, .NET).

      Also, whole program optimization can be (and is) used to determine which functions are pure even in an imperative language, at which point all optimizations that are applicable to them in pure functional languages also become accessible. Though I agree that, in practice, optimizers are only moderately good at that.

      However, this wasn't why Haskell scored so well. Its advantage in the test wasn't that it's pure, but that it's explicitly lazy by default, and therefore defers computations as much as possible. If they're never needed, they will never happen.

      Of course, while laziness can result in such spectacular speed-ups for corner cases, it brings a penalty when result of a computation is definitely going to be used - you pay for the overhead of all the thunking involved. Again, in theory, the compiler can use whole program flow analysis to figure out when there's no point in deferring the computation, but, so far as I know, as good as GHC optimizer is, it still can't get it right in many real-world cases.

      On a side note, expecting further significant advances in optimization fields makes sense (considering how far we've got in the last 20 years already), but in order to be meaningful, you have to assume that it applies to all languages, not just FP. So I wouldn't be surprised if, in 20 years, we'll have a Haskell compiler that'll be able to parallelize code perfectly, and use eager evaluation wherever the difference is unobservable; but if so, we'll probably also have Java compilers that can do near-perfect purity analysis, and then apply the same optimizations...

    221. Re:"functional programming languages can beat C" by phantomfive · · Score: 1

      lol you remind me of a project I was working on where I actually was implementing different type morphology in C for my half of an embedded project (because the library I had been working on was used in many places, thus needed different pieces of code on different projects), and someone working on a different section got so mad at me in front of the project supervisor, saying, "Why do you use function pointers?? The normal way is to just call the function straight!! Why don't you do that like everyone else??" I'm sure I must have had a confused look on my face as I said, "well......that's how you do polymorphism in C, right?" He had nothing to say, and the supervisor just laughed, and after that the employee didn't bother me anymore (he didn't talk to me for a week either, but he got over that).

      For a while I was very obsessed with runtime type binding, which is done in objective C and a lot of scripting languages. It allows you to write code without using so many ugly casts, and really is better (as long as the runtime actually catches the error instead of continuing on with corrupted input like a lot of early C compilers). As I got more experienced, I realized that it really doesn't matter all that much, far more important than any language construct is the ability of the programmer to organize his code.

      --
      Qxe4
    222. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      Gendo, gendo, how can you take over Japan, then reinvent humanity, then think that a search over 250 gigapoints is a large space? Look into tree culling algorithms: since this isn't actually a graph search but a tree search (because fare cycles are nonsense), you can cut that space down enormously. Given that almost the entire search is branch factor, it's quite likely that a sophisticated implementation would search less than a hundred thousand nodes.

      I'm going to say it again: this is not a complex problem. Not even close.

      Remember that this work used to require dedicated intelligence (i.e. a travel agent)

      So did the work that's now done by spreadsheet. What's your point?

      --
      StoneCypher is Full of BS
    223. Re:"functional programming languages can beat C" by stonecypher · · Score: 1

      That said, the code doing the searching for Orbitz uses algorithms and architectural techniques that would take so much more "scaffolding" in C++ that it would not only hamper maintenance of the code, it would likely hamper innovation and invention of new algorithms and functionality.

      This seems to be a favorite claim of LISP type people. I've never seen an actual example of a LISP framework needing less arbitrary scaffolding, though, that was anything even remotely convincing.

      Indeed, that the C++ datastructure and algorithm system would be so much radically simpler makes it quite likely the other way around.

      Listen, I've been clear that I'd like to take a swing at this. As long as you're just making abstract arbitrary claims about how hard it is, there's nothing I can do to disprove things to you (which seems, again, to be generally the way LISP people like things.) But if you take a look at the real world implementations of complex algorithmic systems, C++ implementations are typically on the order of one third or less the total physical size.

      Don't get so wrapped up in LISP's supposed superiority. It always comes down to vague handwaving about scaffolding. If the system is so difficult and complex, the "scaffolding" is a vanishingly tiny portion of the actual code. Give me a LISP system you think is intractable in C++, and I will take the time to change your mind.

      --
      StoneCypher is Full of BS
  2. Faster anything is good. by erick99 · · Score: 1

    Even though Internet throughput seems to be increasing (bandwidth) in leaps and bounds, the server is often a bottle-neck. Anything that is faster is a welcome addition to life in the very, very fast lane.

    --
    http://www.busyweather.com/
    1. Re:Faster anything is good. by InsertWittyNameHere · · Score: 4, Funny

      Not at the expense of having to learn LISP! I'd rather use dialup.

    2. Re:Faster anything is good. by drsmithy · · Score: 2, Insightful

      Even though Internet throughput seems to be increasing (bandwidth) in leaps and bounds, the server is often a bottle-neck.

      What ? You can buy a quad-core, multi-gigabytes-of-RAM machine for under US$500.

      For web serving, if your webserver hardware is the bottleneck, You're Doing It Wrong.

    3. Re:Faster anything is good. by EdZ · · Score: 1

      You can, but I wouldn't expect it to hold up well under constant heavy use.

    4. Re:Faster anything is good. by bennomatic · · Score: 2, Funny

      Hah. Last time I used LISP (well, really, Scheme, since it was at Berkeley), I was on dial-up!

      I remember thinking that there might be something wrong with the dial-up connection the night before the first big project was due, so going into the lab at 2am. The dial-up was not the problem, as it turned out. It was the fact that I wasn't alone in waiting until the last minute to test my code. There were 500 students on that brand new DEC 5400, all writing recursive, interpreted code, and apparently doing so badly enough that such difficult tasks as accepting a username and password were beyond the abilities of the server.

      --
      The CB App. What's your 20?
    5. Re:Faster anything is good. by berend+botje · · Score: 1

      Why not? You can saturate any commercial network link with a 100 MHz Pentium machine easily.

      If you do some heavy scripting on the machine, it might cave a bit. But if your quad-core machine doesn't hold up, then indeed You're Doing It Wrong.

    6. Re:Faster anything is good. by Fulcrum+of+Evil · · Score: 1

      I would. Of course, I'd spend $800 and get the supermicro board and a good psu. Unless you buy the worst chinese crap, it's going to work all the time until it dies in 3-5 years. Web serving isn't all that intensive.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    7. Re:Faster anything is good. by iluvcapra · · Score: 1

      There were 500 students on that brand new DEC 5400, all writing recursive, interpreted code, and apparently doing so badly enough that such difficult tasks as accepting a username and password were beyond the abilities of the server.

      You know the old saying, "Lisp programmers know the value of everything and the cost of nothing..."

      --
      Don't blame me, I voted for Baltar.
    8. Re:Faster anything is good. by Anonymous Coward · · Score: 0

      There is one case you're forgetting: custom web applications that run on fixed hardware. I work for a company that produces very heavy web applications that are to be run on a 400 MHz Intel CPU with 256 MB of RAM and 1 GB disk space. We can't just "throw more hardware at it" in this case and there are quite a few like it... How I wish you were 100% right...

  3. Disgusting by Anonymous Coward · · Score: 5, Funny

    Imagine a small alternative to Ruby on rails, supporting the development of any web application, but much faster.

    It's disgusting that these LISPers aren't content with their own perversion, but have to try to attract others to the gay lifestyle.

    1. Re:Disgusting by Anonymous Coward · · Score: 1, Funny

      It's disgusting that these LISPers aren't content with their own perversion, but have to try to attract others to the gay lifestyle.

      You're confused fellow AC. That's Apple's territory.

    2. Re:Disgusting by Anonymous Coward · · Score: 1, Funny

      but much faster.

      Faster than Ruby on Rails? Inconceivable!

    3. Re:Disgusting by Anonymous Coward · · Score: 0

      Are the mods on crack? I posted this as a troll. What is so funny about it that it was modded up to 5?

  4. An alternative by Ed+Avis · · Score: 2, Interesting

    You might also be interested in SMLserver which embeds Standard ML into Apache, and apparently is pretty fast.

    --
    -- Ed Avis ed@membled.com
  5. Perl is faster than C, too. by Anonymous Coward · · Score: 5, Interesting

    And Java is faster too!

    (rolls eyes)

    Different tools are good for various solving various problems.

    Yeah, I know certain library routines in certain languages are better than others.

    Interpreted languages, in general, are not faster than compiled languages. Period.

    This "faster than C" canard keeps getting trotted out and shot down every time.

    Well, there is one language faster: assembly.

    1. Re:Perl is faster than C, too. by MADnificent · · Score: 4, Insightful

      As you hinted at Common Lisp being an interpreted language, a clarification is in place.

      Most Common Lisp implementations are compiled. As it has been for some time now. Some lisp implementation compile the code themselvel (SBCL for instance), others walk around and compile C-code (ecl for instance).

      An overview of free CL implementations can be found at http://www.cliki.net/Common%20Lisp%20implementation .

    2. Re:Perl is faster than C, too. by bill_kress · · Score: 2, Interesting

      Actually, there are things you can do with Java/C# that you can't do with C period.

      C (and even assembly) can't realize that the same inputs to a routine always cause the same output, and therefore cache the return value and just return it (not without a lot of buggy, custom code anyway). (I'm not saying Java/C# DO this, they may--I understand they were working on it... But just trying to give you an idea of what CAN be done)

      Java/C# do compile to assembly by the way--only the parts that are run often. And the compile step can know a lot more about the runtime configuration of the system.

      Currently these kind of optimizations don't actually have Java running faster than C, currently it runs about 1/2 the speed on average and significantly less for some operations. A very few operations can be faster.

      The real issue is, when Java 7, 8 or 9 comes out, ALL java code ever produced will run faster without touching the compiled system.

      All I'm really doing is offering a counter to your discussion about assembly being clearly faster--Logically I assumed it would be too--just makes sense--but I assumed wrong.

    3. Re:Perl is faster than C, too. by pz · · Score: 1

      Interpreted languages, in general, are not faster than compiled languages. Period.

      This "faster than C" canard keeps getting trotted out and shot down every time.

      And someday we'll all understand the fact that interpreted languages stopped being interpreted a long time ago and are now compiled before execution, rendering the only difference between a classic compiled language (like, say, C) and an interpreted language (like, say Lisp) is that there's a read-eval-print loop (REPL) interface to the latter. Every time you type an expression into a REPL the compiler gets fired up to process that input into the target language that then gets sent to an execution engine. For modern systems, there really isn't much of a difference between interpreted and compiled languages.

      To paraphrase one snarky comment to twist it into another, this "interpretated languages are slower than compiled languages" canard keeps getting trotted out and shot down every time.

      --

      Put my fist through my alarm clock with its ding-dong death inside my ear. - The Blackjacks.
    4. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      Doesn't the argument go something along the lines that higher level languages describe more about the problem and as such are can be optimised to a greater degree than C?

      I think it's a good argument, but it does rely on the compiler/JIT being smart and being backed with a lot of good research.

      One good example of something a highlevel language can do nicely regards pointer aliasing. In C, prior to the restrict keyword, some optimisations could not be applied since the compiler has to generate code to handle all cases it cannot determine to not happen, including aliased pointers. If you use a high level languages where pointers are hidden (Java), or gone all together (Haskell) the compiler/JIT has a lot more freedom to optimise.

    5. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      Same input to a routine SOMETIMES cause the same output.

      Side effects period.

      If you define "output" as the whole environment, your statement can be true. But to apply caching for values, you would have to map the set of environments to the set of inputs. Additionally, your inputs may come from the environment (think of global variables), so you may have to map the set of environments to itself.

      I guess (only guess, I'm not sure) that it would be impractical for imperative languages to implement such a caching mechanism.

      However, it may be practical (for functions that are called with a narrow range of inputs) for (pure) functional languages.

    6. Re:Perl is faster than C, too. by jonaskoelker · · Score: 1

      Actually, there are things you can do with Java/C# that you can't do with C period.

      Really?

      C (and even assembly) can't realize that the same inputs to a routine always cause the same output

      I think the volatile keyword means an external agent can modify the contents of a variable, and if you don't specify volatile, no such agent can. So for all the non-volatile stuff, the compiler can perform the same static analysis that a Java/C# compiler does to decide whether a function has your specified behavior or not.

      And if you're not happy with it, in GCC you can annotate your functions. Wrap the annotation in a portable macro (that does, say, nothing on non-gcc compilers) and Bob's your uncle.

      when Java 7, 8 or 9 comes out, ALL java code will run faster

      And what's to stop people from writing a linker which does some "post-production" optimizations on the object code? If the compiled C code stores as much symbolic information as the Java code, I'd guess you could do a lot of stuff that's typically done in the compiler to the object code (dead write elimination if they're not done yet).

      Also, note that traversing data structures representing byte code isn't free. If later JVMs do more work to optimize code before running it, I predict they will take longer to start up.

      From a theoretical standpoint, your C compiler could be cat(1) if you have a sufficiently sophisticated runtime. Then you can do all sorts of crazy stuff at runtime.

      I think the best kind of argument which is similar to yours is "let's look at practical achievements".

      Are people shipping fancy linkers that speed up C code? No, they're not. Are JVMs employing fancy optimization techniques at run-time? Yes, they are. Is C substantially faster than Java at run-time? Yes, it is.

      The real issue is, when Java 7, 8 or 9 comes out, ALL java code ever produced will run faster [...].

      It'll still be slower than all the C code out there.

      Here's a car analogy: once $BRAND1 finds a more efficient combustion process, all their cars go from 50 to 60 miles per fuel cell that same day. Let's compare to $BRAND2, whose cars run 100 miles per fuel cell today. Which do you want? 60 or 100? Remember: the biggest number is the best here.

    7. Re:Perl is faster than C, too. by osu-neko · · Score: 1

      Actually, there are things you can do with Java/C# that you can't do with C period.

      Are you claiming C isn't Turing-complete, or just making patently false statements to troll?

      C (and even assembly) can't realize that the same inputs to a routine always cause the same output, and therefore cache the return value and just return it (not without a lot of buggy, custom code anyway).

      Ah, I see. You just know so little about C and assembly that such a preposteriously absurd statement seems possible...

      In fact, this sort of thing tends to be done more reliably in C or assembly than in any other language, since it doesn't rely on the compiler's guesswork to try and estimate whether to engage in this sort of optimization or not, it instead relies on the programmer's knowledge, and any decent programmer is more knowledgeable than the machine he or she is programming.

      Although, if you're a script-kiddie, what you say might be true for you.

      --
      "Convictions are more dangerous enemies of truth than lies."
    8. Re:Perl is faster than C, too. by jelle · · Score: 1

      "C (and even assembly) can't realize that the same inputs to a routine always cause the same output, and therefore cache the return value and just return it"

      The 'const' function attribute does that and works fine: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

      And, C compilers have performed such optimization automatically on a much finer scale than functions for ages (common subexpression elimination), and there really is no reason why future versions won't do it just as much, and on all the same scales as java compilers/vm's eventually will.

      "The real issue is, when Java 7, 8 or 9 comes out, ALL java code ever produced will run faster without touching the compiled system."

      Sure, a future version will beat something that exists today, future versions of java vm's will be faster than current versions (thank $DEITY)... But so will C compilers... C compilers beat java vm's today, and there is nothing about the java language that can't be done with C, see for example http://llvm.org/

      Quite possibly the future of executables (for certain types of executables) is more towards the VM/jit approach, but that is language independent.

      While many languages are much easier to use than C (in their application areas), saving development time, and can be for all intents and purposes as fast as it needs to be, saying they will be faster than C will be, is falsely assuming that C compilers have stopped developing further... Perhaps faster than C is today, but not faster than it will be.

      imho, the bucket of gold at the end of the rainbow is there where you can choose your programming language freely, interface across language barriers with ease, and build a final program from such a mixture of languages if needed.

      --
      --- Hindsight is 20/20, but walking backwards is not the answer.
    9. Re:Perl is faster than C, too. by osu-neko · · Score: 1

      And someday we'll all understand the fact that interpreted languages stopped being interpreted a long time ago and are now compiled before execution,

      This is well understood.

      ... rendering the only difference between a classic compiled language (like, say, C) and an interpreted language (like, say Lisp) is that there's a read-eval-print loop (REPL) interface to the latter.

      That's the common misconception. It overlooks the fact that most compiled languages are slower than C, and C is slower than assembly, due not to the fact that one is compiled and one is interpretted, but to the fact that compiler-based guesswork is often sub-optimal to better-informed choices made by intelligent programmers when deciding exactly how to optimize a bit of code. Even C traditionally has the option of inline assembly because C programmers recognized that assembly is faster. It has nothing to do with one being interpreted vs. compiled. It has to do with whether the machine code was produced by an automated system or an intelligent agent, and the degree of closeness of that agent to the machine code. The further the agent abstracts away from it, the less optimal the output can be made.

      --
      "Convictions are more dangerous enemies of truth than lies."
    10. Re:Perl is faster than C, too. by ratboy666 · · Score: 1

      Why would LISP be interpreted? (that is your implication, is it not?).

      http://www.ffconsultancy.com/languages/ray_tracer/index.html

      Scheme (unadorned) is 30% slower that g++.

      http://dan.corlan.net/bench.html

      Choice quotes from the last page:

      " Programming a 1 GHz Pentium [fastest, 1000$, 2002 PC] in Perl is like programming a 10 MHz something [overclocked, 50$, 1982 Z80-based ZX Spectrum] in FORTRAN!

      This is no big surprise as we are looking at the classical trade-off between the power of a language (allowing the programmer to express something in a compact way) and the performace of an implementation (which classically was related to the language being close to the machine representation).

      However, the huge exception is CommonLisp. Lisp is the most powerful language that is, representing the classical extreme choice for expressive power instead of efficient implementation. ...
      For new projects in which one is free to choose the language, one should choose Lisp."

      Here's one where Visual Basic .NET beats C:

      http://www.fourmilab.ch/fourmilog/archives/2005-09/000588.html

      Java beating C:

      http://openmap.bbn.com/~kanderso/performance/java/index.html

      Of course C is an extremely primitive language. It is possible to (on current hardware) write a C program to best most other systems. But, a proper program is much more difficult!

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    11. Re:Perl is faster than C, too. by Phantom+of+the+Opera · · Score: 1

      Interpreted languages, in general, are not faster than compiled languages. Period.

      Excellent point. Better implementations are faster than poor implementations. Period.

      I'm sure the authors of this web server would argue that lisp makes it easier to write a better implementation and concede that any such implementation could also be written in C.

    12. Re:Perl is faster than C, too. by TheRaven64 · · Score: 2, Insightful

      C (and even assembly) can't realize that the same inputs to a routine always cause the same output, and therefore cache the return value and just return it (not without a lot of buggy, custom code anyway).

      C can't because C is a specification. Now let's talk about implementations. If we're talking two of the popular open source ones, GCC and LLVM, you have __attribute__((const)) and __attribute__((pure)), which mark a function as not reading and not modifying global memory, respectively. A function market with the const attribute will always return the same value given the same inputs.

      Of course, these are hacks, and are only required when the compiler can't see the function body and infer these properties itself. Both LLVM and GCC do inter-function constant propagation and LLVM does specialisation too so, if the function body is available while it is compiling the call site, it will generate a specialised version of that function for the specific set of arguments and can inline it. If it evaluates to a constant, or a reused expression, then something like the redundant subexpression elimination pass will remove the duplication.

      Please can we stop with this nonsense that there are 'compiled languages' and 'interpreted languages'. You can compile or interpret any language. A compiler is just a partial evaluation of an interpreter on its input. If you decide to implement C by compiling each compilation unit to LLVM IR and then doing (and caching the results of) link-time optimisation when you run the program, you get most of of the advantages of a JVM. Similarly, if you statically-compile Java you get a different performance profile to JIT'd Java. Which is faster depends on your code and your compiler.

      And yes, before you as, I have worked on a C compiler and written a compiler for a dynamic language (Smalltalk).

      --
      I am TheRaven on Soylent News
    13. Re:Perl is faster than C, too. by msuarezalvarez · · Score: 1

      Same input to a routine SOMETIMES cause the same output.

      Well, the fact thatyoucan most of the time tell wheter a function ALWAYS causes the same output upon the same input is what makes functional languages orders of magnitude simpler to optimze...

    14. Re:Perl is faster than C, too. by DarthVain · · Score: 1

      Thinks about what it would take to code a web server in assembly.... /killself

    15. Re:Perl is faster than C, too. by msuarezalvarez · · Score: 1

      C (and even assembly) can't realize that the same inputs to a routine always cause the same output

      I think the volatile keyword means an external agent can modify the contents of a variable, and if you don't specify volatile, no such agent can. So for all the non-volatile stuff, the compiler can perform the same static analysis that a Java/C# compiler does to decide whether a function has your specified behavior or not.

      And if you're not happy with it, in GCC you can annotate your functions. Wrap the annotation in a portable macro (that does, say, nothing on non-gcc compilers) and Bob's your uncle.

      The fact that you replied talking about volatile means either that you have no idea what you are replyting to, or that you completely missed the point.

    16. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      Java _is_ faster.

      "I didn't know what language to use for this project, so I decided to do an experiment. I wrote the LCS algorithm in a bunch of different languages, to compare how complex the code was, and how fast it ran. I wrote the comp bio algorithm in C, C++, OCaml, Java, and Python, and recorded the results. What I got timing-wise for running the programs on arrays of 2000 elements each was:

              * C: 0.8 seconds.
              * C++: 2.3 seconds.
              * OCaml: 0.6 seconds interpreted, 0.3 seconds fully compiled.
              * Java: 1 minute 20 seconds.
              * Python: over 5 minutes.

      About a year later, testing a new JIT for Java, the Java time was down to 0.7 seconds to run the code, plus about 1 second for the JVM to start up. (The startup times for C, C++, and Ocaml weren't really measurable - they were smaller than the margin of error for the measurements.)" http://scienceblogs.com/goodmath/2006/11/the_c_is_efficient_language_fa.php

    17. Re:Perl is faster than C, too. by Shados · · Score: 3, Interesting

      The main difference is that C is, and always will be, optimized at compile time. Virtual machine languages can dynamically optimize themselves at runtime. Some of the later iteration of the Java and .NET runtimes can notice patterns at runtime (which is an initial performance hit, obviously), and then make assumptions about further calls, and just making sure that they're not messing up (my understanding is that lately Java has made leaps and bounds in that direction).

      Then when the pattern "breaks", it reoptimize the piece of code without the assumption. Depending on the system, that can make tremendous performance improvements. As long as things are optimized at compile time only, you won't be able to go that far. Other examples include system wide memory compacting, doing away with useless locks at runtime, etc.

    18. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      A few combinations do general make C fastest for speed comparisons. This observation is based on several factors:

      1. Pure C can be extremely close to assembly. Thus you're pretty close to bare metal.

      2. If close to bare metal isn't close enough, you can always through assembly into your C program and call it directly.

      3. Most operating systems are written in some form of C, therefore C programs general can hook into the OS fairly tightly for many real-world issue such as IO and threading.

      4. C is widely used for scientific computing, as a result there are many specialized compilers, optimizations, and libraries that can really push speed challenges. Fortran can make some similar claims, but IMO it seems to be declining.

      5. You can almost always "cheat" in C. If memory is slow you can access it directly and bypass system overhead. If you're being bogged down by function call overhead you can write the function as a macro, or start doing straight jmps to the code. If you want to cheat on math libraries use CUDA.

      C has more than it's share of problems and to be honest, 99 times out of a 100 someone will do something stupid with C that later generation language would have taken care of and done better. But (personally) if I ever need unadulterated raw speed, I go with C.

    19. Re:Perl is faster than C, too. by gbjbaanb · · Score: 1

      in other words, it can spend a fair few cpu cycles (plus VM memory) continually recognizing these patterns, and recompiling the code.

      Sounds just like it goes faster to me!

      C is compiled once, in a long, slow compile that can implement lots of optimisations that your JIT cannot. The only real benefit of JIT is that it knows the CPU features it can use that you might have to ignore on a pre-compile step (eg SSE).

      Also, in my experience, the high-level managed languages have additional locks to protect you - last thing you want is a thread-unsafe app going wonky because the JIT thought it knew a lock was unneeded (it a seriously difficult task, most VMs ensure locking around data structures on multi-cpu pcs just to be safe).

    20. Re:Perl is faster than C, too. by Shados · · Score: 1

      C is compiled once, in a long, slow compile that can implement lots of optimisations that your JIT cannot

      Those are recognised and embedded in the bytecode at compile time. Java and .NET compilers are quite aggressive in that regard, too. And the overzealous lockings date from older versions of the managed languages. Some do remain (so static variables can actually be useful in multithreaded environment!), but as a whole its done much better. Yes, its a seriously difficult task, but it has been solved.

      Don't get me wrong, I'm not blind: I wouldn't write a full featured word processor in Java. Some tasks are just better done in lower level code. But managed languages really perform well now, and for highly dynamic tasks in an ever changing environment, they definately can do at least similarly, and sometimes better. Even more so in .NET where you can drop to the bytecode and do pointer arythmetics as needed, so C loses these advantages.

    21. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      Of course you can always write your C program to make runtime optimizations, too; you can also write a program in C that uses virtual machines to run C code. The question is whether the effort is worth it when you could just use a different language. I don't mean this to say that C is the father of all languages or some other untrue BS like that, only that programming languages are only constructs and API sets and a basic language like C can always have missing constructs built atop it. I realize some will see this as a banal point, but I can assure you it's one a lot of code monkeys don't realize.

    22. Re:Perl is faster than C, too. by Actually,+I+do+RTFA · · Score: 1

      The main difference is that C is, and always will be, optimized at compile time. Virtual machine languages can dynamically optimize themselves at runtime. Some of the later iteration of the Java and .NET runtimes can notice patterns at runtime (which is an initial performance hit, obviously), and then make assumptions about further calls, and just making sure that they're not messing up

      Actually, C and C++ can also notice patterns at runtime. An analyzer is set up to observe the program at runtime, and it can be optimized and relinked. Granted, this only happens a few times at the dev site, but the cost for it only occurs there as well.

      --
      Your ad here. Ask me how!
    23. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      lisp isn't solely an interpreted language, but can be compiled too, and very often is.

      So you may be true about interpreted languages, but at the same time you kind of miss the subject

    24. Re:Perl is faster than C, too. by synthespian · · Score: 1

      SML ray tracer vs. C++ ray tracer.

      High-level "nifty shit" language is 30% faster than C++.

      http://www.ffconsultancy.com/languages/ray_tracer/comparison_cpp_vs_sml.html

      --
      Main difference between the BSD license and the GPL license: one is from California and the other is from Massachusetts
    25. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      It's also pretty easy to tell if a C function always causes the same output from the same inputs. Just check if no global/static variables are accessed in the function, and that it only calls functions known to be just as clean.

      I may have missed some detail, but I honestly can't see any reason why it would be hard to implement such an optimization in a C compiler.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    26. Re:Perl is faster than C, too. by m50d · · Score: 1

      This is always trotted out, but it ignores the last fifteen years or so of C compilation. If that kind of dynamic optimization really did make the program more effective, the C compiler would be within its rights to output a JVM with some hard-coded Java to do what's needed. And to a very limited extent it does things on those lines (advanced C compilers can e.g. output a program that for a repeated branching construct will, rather than using compile-time branch prediction, switch to an implementation of the loop with differing predictions based on the runtime measurements). The reason this isn't taken further is that it's not generally such a big performance win, especially if you'll allow the C programmer to do profile generation on a few test cases and then build this profile in statically.

      --
      I am trolling
    27. Re:Perl is faster than C, too. by msuarezalvarez · · Score: 1

      Even if you decide not to allow separate compilation (so that you can make decisions having *all* the relevant code available at compile time) doing this for C is very, very, very difficult.

    28. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      > So for all the non-volatile stuff, the compiler can perform the same static analysis that a Java/C# compiler does to decide whether a function has your specified behavior or not.

      No it can't. It can't recognize that a function happened to be called 30 times in the last second with the parameters (1, 5, "Hello") and returned 17, and just return 17 for those values--and the next day, do the same thing for different values.

      Sure you could program it to, but it would all be your code--C cannot do it for you on every single function, it wouldn't make sense (then C would need a runtime like java--it would no longer be C)

      Also--the language itself would make this impossible. Java can know for sure that nothing is modified without the runtime's knowledge. There are no pointers in Java, and the runtime can analyze a class to ensure that things it relies on haven't changed. C could not do that generically, You would have to double the size of every method to get that kind of functionality.

      > And what's to stop people from writing a linker which does some "post-production" optimizations on the object code?

      You'd have to relink. I suppose linking could be done at runtime automatically, and C could have a runtime that was updated and understood how to restructure the code and add new optimizations. It would probably have to eliminate pointers and have a pretty serious runtime component to do so. Perhaps it could take on a new name--call it C# I guess.

      >Also, note that traversing data structures representing byte code isn't free. If later JVMs do more work to optimize code before running it, I predict they will take longer to start up.

      Not really, they can (and do) just make the JVM more efficient. The chances also tend to make the JVM smaller and faster to load.

      >Are people shipping fancy linkers that speed up C code? No, they're not. Are JVMs employing fancy optimization techniques at run-time? Yes, they are. Is C substantially faster than Java at run-time? Yes, it is.

      What makes you say it's substantially faster? Until you get fairly high on the C optimization scale, Java tends to be faster--There was a programming challenge on Cedric's blog that became really interesting--people optimized the hell out of a routine and then re-ported it to a few languages. I believe the Java routine was slightly faster than the C routine (including startup) until it was compiled above -O3, then the differences were minimal (IIRC). In a few cases java is much worse (maybe even 10x), but for most stuff it tends to be 2x as slow.

      One of the worst cases is floating-point math where Java refuses to use the math co-processor because they do not all return the same results for a given operation--this infuriates the graphics folks who don't care about accuracy anywhere near as much as speed (and here lies one of the REAL advantages of C, you can't fix this without recompiling the java source--a daunting task--where in C you just link against a different library.)

      Anyway, the point is, compare Java and C's speed to say that of Python and Ruby (100x slower) and you'll see that Java and C are extremely closely tied.

      I've used Java on multiple embedded platforms with oddball chipsets and very low power (including high performance graphics).

      So Can you back up your "Substantially faster" statement? Where do you get your data? Are you just using the same logic and assuming it has to be faster?

      http://shootout.alioth.debian.org/gp4/benchmark.php?test=nbody&lang=all

    29. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      It can work even with separate compilation. You just need a way to store information about each compiled function somewhere. It would of course be simpler to implement without separate compilation, but that's not a constraint specific to C.

      Why is it very difficult to do for C? You can do it incrementally:

      - Start by applying the optimization just to functions which only have arguments passed by value (no pointers allowed), don't call any other functions and don't access static/global variables. This already optimizes a number of cases.
      - After that, apply the optimization to functions which follow the previous rules but now allowing them to call other functions in the same file (which also follow the same rules).
      - After that, account for the separate compilation problem (either not allowing it or saving helpful information about other modules somewhere), which will allow you to optimize functions which call functions in other files.

      Which of these steps would be terribly hard?

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    30. Re:Perl is faster than C, too. by dkixk · · Score: 1

      (rolls eyes)

      Interpreted languages, in general, are not faster than compiled languages. Period.

      Lisp is not an interpreted language. Period. It is an interactive language. If an implementation decides to achieve this with an interpretor, that is possible. However, there are implementation for which all code is compiled. SBCL is such an implementation. I would include a snippet of the disassembly from SBCL but /code seems to think that posting such is using to many 'junk' characters.

    31. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      >The 'const' function attribute does that and works fine

      Really?

      I don't think you get it. I'm talking about a regular function that takes, say a and b and returns the sum of a and b. Can C really notice that you happen to be calling it with 3,7 a lot and cache the return value of 10, then the next day notice that you are calling it with 1023,2042 and return 3065?

      Or can C notice that you almost always call a function with a parameter that causes a particular path through that function, then compile (to binary, not bytecode) a version of that function that contains only code used in that path and use it for a particular sub-set of parameters?

      If so, C has changed a lot since the last time I used it.

      A program run by a VM has much more potential than one run without.. currently we are only scratching the surface of what can be done and java is already running at the same speed as C!
      (Well faster than some compilers, slower than others for a given solution--but Java is rarely more than a couple percent off)

    32. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      Please explain how the same function with parameters "1, 2, 3" returns one thing one day, and one thing in the other (assuming it has no side effects or access global/static variables).

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    33. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      A function, sum(1,2,3) returns 6.

      Let's say it's called 1000 times with the same parameters, it could be short-circuited to simply insert a 6 instead of calling the funciton.

      The next day, it's called 1000 times with 1,5,5000.

      After analyzing ALL inputs (including references from within the method to outside objects) It could be short-circuited to return 5006.

      This is not hard within the JVM, it is virtually impossible within C. This is why you are having trouble comprehending what the JVM can do--I can't blame you, it takes a while to grok the difference between code running natively and code that can be analyzed at runtime.

    34. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      It would be trivial to do it in C actually... Just put wrapper code at the entry and exit point of the function to insert the arguments and result into a small hash table. Done, without a runtime.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    35. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      Exactly, now do it for every single function, automatically determining (by call count and mutability of external references) if it makes sense or not. Now you DO have a runtime.

      Also, how do you prove that pointers haven't modified the values you depend on without checking each one?

      And that's just one of hundreds of things that are possible with a VM, none of which you can do with native code.

      --Compiling code to native for a given state of a variable who's state rarely changes, eliminating calculations on that variable as though it was a constant.
      --Compiling a second instance of that method if the variable DOES change, being able to alternate between which of the two you call at will.
      --Inlining code like that (or not) based on runtime statistics.
      --Taking code written as single-threaded and throwing multiple threads at it when it determines that two paths don't interact. (This could be done at compile time as well, but could be done more efficiently with code profiling information in memory.)
      --Improving the efficiency without recompiling (Or, you could look at Java as ALWAYS recompiling to machine language)

      In fact, that may be the point that the C people here are missing. How can C possibly compete with a language that compiles to machine language with more information than the C compiler has at compile time?

      Currently C keeps up (Most benchmarks seem to have a few C compilers running faster than java and a few slower, but the difference is often under 10% both ways) but C is on it's umpteenth year of optimization, whereas the JVM has only been compiling for a few years now and has a lot of improving to do...

      http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all&box=1

      Look at some of those results (The best code submitted by expert programmers for each language)--Java and C are always in the top few, C is almost always a few ticks quicker, but virtually tied.

      If you think the C code must suck, please help C win by improving their code--I'm fairly sure it's already been streamlined past what a mortal programmer can improve in most of those languages. Until someone improves these I'm going to go with C and Java being the same speed, but Java improving more rapidly.

    36. Re:Perl is faster than C, too. by Anonymous Coward · · Score: 0

      It would be trivial to do it in C actually... Just put wrapper code at the entry and exit point of the function to insert the arguments and result into a small hash table. Done, without a runtime.

      Very good, now can you do it for any arbitrary function at runtime, without recompiling?

    37. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      Exactly, now do it for every single function, automatically determining (by call count and mutability of external references) if it makes sense or not. Now you DO have a runtime.

      At compile time, you would make the safety checks to see if a function is safe enough to be optimize (it certainly can't use global variables, unless the contents of those are also to be recorded; changing global variables would be a no-go of course). And it would only be able to call equally safe functions.

      I think you're blurring the definition of a runtime a bit. I don't consider inserting trivial wrapper code around a function's contents a real runtime system, but if you want to call it that, go ahead. That's what things like gprof (profiler) do, and it works just fine.

      Also, how do you prove that pointers haven't modified the values you depend on without checking each one?

      The same way that the runtime would do it. The runtime would also have to check such things (and that's if they dare to apply this optimization to functions accessing foreign objects).

      --Inlining code like that (or not) based on runtime statistics.

      Is that improvement worth it when you have to constantly gather statistics about every function call? There's two sides to this coin, you know. Does Java implement that?

      --Taking code written as single-threaded and throwing multiple threads at it when it determines that two paths don't interact. (This could be done at compile time as well, but could be done more efficiently with code profiling information in memory.)

      How would it prove that the two paths don't interact, in a way which can't be done by a compiler? The compiler can also simulate the running of code.

      An example would be helpful if you think I'm wrong in this case.

      In fact, that may be the point that the C people here are missing. How can C possibly compete with a language that compiles to machine language with more information than the C compiler has at compile time?

      That's not the whole picture. Java has more features which add a certain overhead to several operations (function calls, accesses to arrays, type handling and so on).

      I accept that having a smart runtime can be helpful in some cases, but it's not like you can't make such a runtime for C either. The fact is that so far C's performance is great without one.

      Look at some of those results (The best code submitted by expert programmers for each language)--Java and C are always in the top few, C is almost always a few ticks quicker, but virtually tied.

      I looked, and it's a bit weird that the results for C and C++ often differ by a lot (which makes me think the programs are not that optimized, as for small programs like that it should be trivial to make C and C++ as fast as each other).

      I assume "elapsed secs" is the most relevant performance statistic.

      Still, either C or C++ are always faster than Java, and in most cases much faster as you can see in these comparison pages:

      http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=javasteady&lang2=gpp&box=1
      http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=javasteady&lang2=gcc&box=1

      I see a lot of problems for which C/C++ are 2 or 3 times faster than Java.

      By the way, it's worth noting that some of these benchmarks do little memory handling and are pretty numerical code which uses few language features. In these cases compiler quality should make most of the difference in results, so Java should fare quite well there.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    38. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      Yes, you are correct. If you were to make C run in a VM and remove pointers (for improved optimization, with pointers around it's harder for the VM to know what can and can't change at runtime). You might also make it cleaner while you're at it, remove stupid compiler tricks like header files. Make it OO as well with memory management (you might as well now that you've got a VM there, it'll be a good deal more efficient than malloc/free for heap memory).

      Yes, you can improve C. Someone should look into that.

    39. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      >>Also, how do you prove that pointers haven't modified the values you depend on without checking each one?

      >>The same way that the runtime would do it.

      The java runtime doesn't have to because it doesn't allow arbitrary pointers to memory. I do kind of wonder about C# and if it affects performance optimizations.

      >Is that improvement worth it when you have to constantly gather statistics about every function call? There's two sides to this coin, you know. Does Java implement that?

      Yes, Java currently collects runtime statistics so that it knows which calls might benefit from compiling to machine language.

      >How would it prove that the two paths don't interact, in a way which can't be done by a compiler? The compiler can also simulate the running of code.

      I admit this one is reaching a bit. You can do a lot of compile-time optimization, but you could use runtime statistics to show which functions might benefit from their own thread.

      >I looked, and it's a bit weird that the results for C and C++ often differ by a lot (which makes me think the programs are not that optimized, as for small programs like that it should be trivial to make C and C++ as fast as each other).

      Since the programs are submitted by language advocates and repeatedly revised, I'm guessing none of them have really big obvious time-sinks.

      I found a lot of those results strange as well--the compiler used often seemed to have more of an effect than the language! There is also one case where functional languages are far faster than C or Java.

      But notice that there are very few edge cases where C is a few times quicker, and mostly they are within a few percent. This is with all Java's VM overhead you mentioned above. It won't take but a few small incremental improvements before Java is regularly beating C--and C's so optimized already I'm not sure how much more can be done.

      If you add heap allocation of small objects (Very common with good OO code), you may find that Java starts to blow C out of the water (at least C using standard malloc). 99% of Java's heap allocation should perform like C's stack allocation, it uses some very neat tricks to accomplish that. I'd actually like to test this sometime, but I don't write much C code these days--not since the early 90's.

      I'm guessing multiple small allocations are what makes the thread-ring test prefer functional languages over the best C/Java times by a factor of 10x+ though.

    40. Re:Perl is faster than C, too. by rbarreira · · Score: 1

      > The java runtime doesn't have to because it doesn't allow arbitrary pointers to memory.

      True, but it would still have to check the contents of the referenced objects, to ensure they didn't change (if the optimization strategy allows for functions with references to be optimized).

      > Yes, Java currently collects runtime statistics so that it knows which calls might benefit from compiling to machine language.

      I meant for the specific case of knowing whether to inline a function or not. Collecting metrics for that seems like a big overhead considering the benefit.

      > Since the programs are submitted by language advocates and repeatedly revised, I'm guessing none of them have really big obvious time-sinks.

      I will definitely compare the C and C++ versions of those problems where they differ a lot, to understand what's happening there. Maybe the problem lies in compiler differences as you said.

      I get your point about memory allocation. There's definitely room for improvement in some C libraries, but I think some of them also have separate heaps for big and small objects.

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    41. Re:Perl is faster than C, too. by bill_kress · · Score: 1

      > I meant for the specific case of knowing whether to inline a function or not. Collecting metrics for that seems like a big overhead considering the benefit.

      I know it collects various metrics, but the big deal right now is JIT compiling. My feeling is there is a lot of room for improvement with the JVM--The JIT compiler is only a few years old.

      Then there are the potential big improvements that could jump it above most assembly language such as Microcode in a CPU or co-processor with the ability to process Java bytecode instructions natively--remember bytecode is MUCH more compact than the x86 assembly instruction set. A powerful, optimized CPU should be able to do much more with it than with x86 code because it wouldn't have to spend so much effort trying to move code in and out of caches--less data does significantly more work.

      In fact, did you know that even in the early 90's, excel and Word, even though they were written in C, used an embedded bytecode VM for code size? (I forget where I heard that, it was when Java first appeared on the scene, so I really should check my references).

      I'm not half as vested in this as I sound--It's just that the OP put out that C can't be beat, and I really think a lot of people miss the advantages of an active runtime. I get the feeling that people think Java is like 100x slower, and yet many of the same people will use Ruby which actually IS 100x slower. Confuses me a little.

  6. Re:Attention Pooftahs and Frenchies by 0100010001010011 · · Score: 1

    Yeah and if it wasn't for their help. We'd still be speaking English!

    And without them, what would Ghostbusters II have used to get into the Museum?

  7. Speed is not all by moon3 · · Score: 0, Redundant

    In terms of readability and maintenance it might be a nightmare (looking at the LISP code).

    The benchmark seams biased anyway, you can't beat C/C++, really, and the LISP language itself is written in C.

    1. Re:Speed is not all by Anonymous Coward · · Score: 2, Informative

      the LISP language itself is written in C.

      Not at all. Lisp implementations are usually written in Lisp.

    2. Re:Speed is not all by K.+S.+Kyosuke · · Score: 2, Informative

      In terms of readability and maintenance it might be a nightmare (looking at the LISP code). The benchmark seams biased anyway, you can't beat C/C++, really, and the LISP language itself is written in C.

      Very few implementations of Lisp are written in C. Usually there is only a small kernel, and on top of that kernel sits the standard library and the compiler. The kernel often provides only the memory model, the garbage collector, and links to the OS - only the things that can't be written in Common Lisp are in C. Mind you, they *could* be written in some "lower-level Lisp", but since the passing away of Lisp Machines, which ran Lisp Assembly code, nobody seems to bother with this - portable C compilers are ubiquitous and the core itself is portable this way. This means that a compiled Lisp program runs essentially very little C, unless it is collecting garbage.

      The reason for Lisp being written in Lisp is precisely what you're claiming there (only the other way round): A Lisp written in Lisp is much more maintainable than a Lisp written in C. Besides, compiler often serves as a good test suite for itself.

      And as far as "beating C" is concerned, you might want to take a look at Stalin Scheme.

      --
      Ezekiel 23:20
    3. Re:Speed is not all by moon3 · · Score: 1

      Lisp written in Lisp is much more maintainable than a Lisp written in C

      Robust code speaks for itself, or at least the language must allow for it. I can't see LISP being more readable or obvious that C/C++ is.

      Maybe in academic scenarios this is a plus, but in production environment? LISP is another single-paradigm language, with all the woes that comes with it.

    4. Re:Speed is not all by K.+S.+Kyosuke · · Score: 1

      Lisp is *not* single-paradigm, C is - with all the woes that come with it.

      --
      Ezekiel 23:20
    5. Re:Speed is not all by moon3 · · Score: 1

      Well, C++ allows object-oriented, procedural, functional and generic programming. Can this "LISP" do that ? Btw: I've never heard of LISP so I might be wrong and LISP really is something, I thought it is another "Ruby On Rails" kind of glue language for web/html coders.

    6. Re:Speed is not all by Pentagram · · Score: 1

      Well, C++ allows object-oriented, procedural, functional and generic programming. Can this "LISP" do that ?

      In order: yes, yes, hell yes, and you could but probably wouldn't want to.

      Lisp is the absolute opposite of a single-paradigm language. You can rewrite Lisp itself using the macro system into any form you might want, so you can take advantage of any future "paradigms".

      Btw: I've never heard of LISP so I might be wrong and LISP really is something,

      Good grief. I think most programmers could do with more exposure to Lisp, but not to have even heard of it is quite an achievement!

      I thought it is another "Ruby On Rails" kind of glue language for web/html coders.

      It's main domain is for ultra-hard problems such as those encountered in academia, but it really deserves to be more widely used. Its main disadvantages are a lack of recognition, lack of standardised libraries, and the skill level required to use it effectively.

    7. Re:Speed is not all by K.+S.+Kyosuke · · Score: 1

      Lisp is a tiny set of rules for writing expression trees (a data structure, essentially) in a textual format that everybody would agree upon and that would be reasonably suitable for writing by hand. Additionally, it includes some "basic semantics" that you may or may not redefine, in form of a library, to better suit your needs, based on the the problem at hand. Can you write, e.g., a C++ library to create a dialect of C++ that would behave precisely the same way that standard C++ does, only with lazy evaluation of expression terms?

      --
      Ezekiel 23:20
    8. Re:Speed is not all by moon3 · · Score: 1

      We come from different backgrounds, that is obvious to me, some kind of lazy evaluation is being introduced in C++ 0x, Bjarne is looking at it, I believe, but hardly anybody cares. I fail to see how lazy eval. or lazy casting or similar things could help us to have more error-prone, robust, easy to debug and reliable code. Last iteration of the C++ standards only tightened the rules to avoid things like that. I prefer to be in control of things, even if that means a small speed penalty. Runtime code juggling might a nightmare to debug in production environment. Speed is not all, again, thanks and have a nice day.

    9. Re:Speed is not all by K.+S.+Kyosuke · · Score: 1

      I fail to see how lazy eval. or lazy casting or similar things could help us to have more error-prone, robust, easy to debug and reliable code.

      Potentially useless, but canonical example of quicksort:

      qsort [] = []

      qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

      Want to select k-best elements? Just do take k (quicksort input). Laziness reduces O(N.log N) to just O(N) *and* you don't have to construct a heap. More to see here and here.

      I prefer to be in control of things, even if that means a small speed penalty.

      Well, it is Lisp, for one, that gives you the ultimate control of things. :-)

      Runtime code juggling might a nightmare to debug in production environment

      Lua people had this to say to that: "If you don't want to do it, just don't do it." Nobody is forcing you to abuse the Turing-completeness of C++ templates, either.

      --
      Ezekiel 23:20
  8. World's "Fastest" Small Web Server Released, Based by omar.sahal · · Score: 4, Informative

    LISP, the world's second oldest high-level programming language.

    Sorry its the third oldest this is the oldest.
    Designed by Konrad Zuse who also invented the first program-controlled Turing-complete computer. Fortran is the second oldest programming language.

  9. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 1, Insightful

    We would appreciate you folks taking some time to reflect on our servicemen who gave their lives saving your asses in WW I and II.

    I'm sure the rest of the world appreciates your sitting on your neutral asses for the first couple of years of each of those wars...

  10. McDonaldization being the price by rs232 · · Score: 0, Troll

    "Today is Memorial Day in the United States of America. We would appreciate you folks taking some time to reflect on our servicemen who gave their lives saving your asses in WW I and II"

    Actually it was the Soviet Union that broke the back of the German army. And if you liberated us in 1945, then why are you still occupying the place with military bases. The price we are paying being the continued McDonaldization of the place ..

    --
    davecb5620@gmail.com
    1. Re:McDonaldization being the price by osu-neko · · Score: 1, Insightful

      Actually it was the Soviet Union that broke the back of the German army.

      There is a point where oversimplification turns an essentially true idea into an utterly false statement. You passed that point a while back here.

      And if you liberated us in 1945, then why are you still occupying the place with military bases.

      Because you want us to. If you wanted us to leave, we would. There are numerous examples of this.

      The price we are paying being the continued McDonaldization of the place ..

      Given that this is happening everywhere in the world along with modernization, even places where no American soldier has ever set foot, your statement linking the two is utterly absurd.

      --
      "Convictions are more dangerous enemies of truth than lies."
    2. Re:McDonaldization being the price by afabbro · · Score: 1

      "Today is Memorial Day in the United States of America. We would appreciate you folks taking some time to reflect on our servicemen who gave their lives saving your asses in WW I and II"

      Actually it was the Soviet Union that broke the back of the German army.

      True. And of course, quite a definitive comment since the Germans were the only evil actors in World War II.

      Oh wait...

      --
      Advice: on VPS providers
  11. Paul Graham argues by rolfwind · · Score: 1

    that there are really only two very clear style of languages, the C family and the Lisp family, with later languages like Java starting from a C basis but building towards functionalities found in Lisp.

    I wonder what is beyond Lisp and other functional languages, though?

    1. Re:Paul Graham argues by monk · · Score: 3, Interesting

      You aren't looking very closely if you're missing it.

      By "c-like" I believe Graham meant elements of syntax and approach.

      methods declarations in Java take the form:
      return_value name(args)
      {
          statement;
          data_structure.member = assignment;
      }

      A C function looks like:
      return_value name(args)
      {
          statement;
          data_structure.member = assignment;
      }

      The approach stuff is harder to summarize in a post but think of the differences in the use of macros and differences in binding as good examples

      James Gosling is one of the people who called Java a "C-like language that avoided the pitfalls of C++"

      (full disclosure: I used to work for Sun as a Senior Java Architect so my opinion may colored by the chip they put in my brain)

      --
      [-- Trust the Monkey --]
    2. Re:Paul Graham argues by monk · · Score: 1

      well the same thing as always. forth ;)

      --
      [-- Trust the Monkey --]
    3. Re:Paul Graham argues by Anonymous Coward · · Score: 0

      I'd say logic programming languages, such as prolog, would clearly comprise a third style.

    4. Re:Paul Graham argues by sillybilly · · Score: 1

      Somehow being labeled as "Senior Java Architect" seems to me like being made fun of. I would only want to be labeled that if it came with a fat salary, and only for the money, because passionate zeal for the topic would still be nonexistent, because the whole thing is so far off into bloated nontransparent bullshit land, that only retards truly believe in it.

    5. Re:Paul Graham argues by larry+bagina · · Score: 1

      Java is not, by any reasonable standard, closer to LISP than C.

      Let's look at the wankopedia page:

      Influenced by: Ada 83, C++, C#,[1] Eiffel,[2] Smalltalk, Mesa,[3] Modula-3,[4] Objective-C

      The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities.

      The syntax of Java is largely derived from C++

      Not one mention of lisp. But what about lisp?

      Newer languages such as Java and Python have incorporated some limited versions of some of the features of Lisp, but are necessarily unable to bring the coherence and synergy of the full concepts found in Lisp.

      Of course, there's no citation for that.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    6. Re:Paul Graham argues by osu-neko · · Score: 1

      I don't know what it is you're smoking to think that Java starts on a C basis but can you share?

      He's probably basing that on the statements by the creators of the language, who acknowledge this and indeed state it was one of their design goals.

      --
      "Convictions are more dangerous enemies of truth than lies."
    7. Re:Paul Graham argues by Abcd1234 · · Score: 1

      Java is a hell of a lot closer to LISP than it is to C.

      Good lord.

      Your claim to understanding either Lisp or Java is extremely suspect after a statement like that. Last I checked, Java didn't support even the most basic of functional programming features (closures, anyone?), let alone Lisp's more advanced features (eg, it's macro system). I mean, the very heart of lisp is the s-expression, which allows code and data to be treated interchangeably. Java has no such thing, and never will, thanks to it's Algol-inspired syntax.

    8. Re:Paul Graham argues by H0p313ss · · Score: 1

      To all those having a bash at me... Show me the C VM.

      --
      XML is a known as a key material required to create SMD: Software of Mass Destruction
    9. Re:Paul Graham argues by Abcd1234 · · Score: 1

      Because the pedigree of a language is defined by the machine it targets?? Holy shit... you really are incompetent. Hell, by that argument, Java has as much in common with Pascal as it does Lisp.

    10. Re:Paul Graham argues by H0p313ss · · Score: 1

      Because the pedigree of a language is defined by the machine it targets?? Holy shit... you really are incompetent. Hell, by that argument, Java has as much in common with Pascal as it does Lisp.

      Sorry bro, but if you think the syntax alone defines the pedigree then I am not the incompetent one.

      --
      XML is a known as a key material required to create SMD: Software of Mass Destruction
    11. Re:Paul Graham argues by shutdown+-p+now · · Score: 1

      To all those having a bash at me... Show me the C VM.

      Java Language Specification does not require a VM (it's a separate spec). Hence why we have e.g. GCJ.

      On the other hand, there are plenty of C interpreters out there, including bytecode interpreters (which would qualify as a VM). A simple Google search would bring up a few, but perhaps the most widely used one is Q3VM in Quake 3 engine.

    12. Re:Paul Graham argues by Anonymous Coward · · Score: 0

      How much of the Lambda calculus does Java have in common with Lisp?

      How much of the JVM's approximation of a Von Neumann machine do Lisp interpreters have in common with C?

      Java may have taken the concept of garbage collection from Lisp, but at its heart is Java is a member of the C family of languages.

  12. This guy is my new hero.... by ZosX · · Score: 3, Insightful

    "Automated garbage collection is rubbish" and "Real men don't use floating point" were two of the most interesting and compelling arguments I've read all week. And using LISP as a web platform framework? Fascinating. There were some great ideas back in the days when computers were in there infancy and a lot of them have been abandoned for the most part. Like trinary computing for instance. The building blocks of the computers that you see today were partially designed because of technological limitations at the time. The mechanical underpinnings of the first computers are still present today. I don't care if I'm really wrong about this point (I've been wrong before), but I think computing really needs to transcend a system based on 0s and 1s. Why not abandon the general purpose cpu altogether or at least reduce it to a single core and focus on multiple cores of different types of chips that are optimized for different types of problems? Larrabee might be an hint of that, though I think that ultimately it will really just be a cost saving measure since the gpu no longer needs to be integrated into the board. I think we may be locked into a future of x86 clones for another 30 years at this rate. The Itanic was a good lesson for intel in how much the market values their older code still being able to run without issue. Forgive my bit of a ramble. Just had a whole bunch of random thoughts there.

    1. Re:This guy is my new hero.... by AsmCoder8088 · · Score: 0, Offtopic

      Very nice pictures indeed (referring to your sig).

    2. Re:This guy is my new hero.... by Sycraft-fu · · Score: 1

      "Real men don't use floating point"

      That is an amazingly retarded statement. Why? Because regardless of how you think computers ought to be designed, they way they actually are designed they have massive FPUs. Modern desktop CPUs have loads of floating point power. This isn't to say they are bad with integer performance, but floating point is where they can really throw down. So, to not use floating point ever is to ignore the major power on a processor. It is to deliberately cripple your code on actual hardware.

      That isn't to say you should just use floating point for no reason. If the number you are storing is an integer, use an integer. However don't start jumping through hoops to do fixed point math or something if you need a fractional result. Let that FPU flex its muscle. It can do a few BILLION floating point calculations per second, after all.

      For that matter, some of the new developments like GPGPU are all floating point. GPUs are designed to be monsters at crunching single precision floating point data in parallel. So, if you wish to have them work on your problem, you'd better be able to use FP data, and to divide it up in to parallel tasks.

      As for some of the things that have died, well there's often good reason: They don't work well. Trinary is an example. The whole reason binary is so effective is you get out of the analogue domain. There's no more uncertainty as to the level of something. It's on or off. Makes encoding and retrieving data much easier. With trinary, you destroy that. Now you are just back to a very coarse analog measurement. Look at some of the modern technologies for encoding lots of data reliably in a small space, like EPRML, and tell me how you make that work trinary.

    3. Re:This guy is my new hero.... by ZosX · · Score: 1

      From the wikipedia:

      History

      One of the earliest calculating machines, built by Thomas Fowler entirely from wood in 1840, was a ternary computer. The only modern ternary computer Setun was built in the late 1950s in the Soviet Union at the Moscow State University by Nikolai Brusentsov, and it had notable advantages over the binary computers which eventually replaced it (such as lower electricity consumption and lower production cost). In 1970 Brusentsov built an enhanced version of the computer, which he called Setun-70.

      [edit] Balanced ternary

      Ternary computing is commonly implemented in terms of balanced ternary, which uses the three digits -1, 0, and +1. The negative value of any balanced ternary digit can be obtained by replacing every + with a - and vice versa. It is easy to subtract a number by inverting the + and - digits and then using normal addition. Balanced ternary can express negative values as easily as positive ones, without the need for a leading negative sign as with decimal numbers. These advantages make some calculations more efficient in ternary than binary.

              "I often reflect that had the Ternary instead of the denary Notation been adopted in the Infancy of Society, machines something like the present would long ere this have been common, as the transition from mental to mechanical calculation would have been so very obvious and simple". (Fowler, 1840)

      [edit] The future

      With the advent of mass-produced binary components for computers, ternary computers have diminished to a small footnote in the history of computing. However, ternary logic's elegance and efficiency is predicted by Donald Knuth to bring them back into development in the future[1]. Possible ways on how this can happen is by the combination of an optical computer with the ternary logic system [2] The simple way to explain this is to compare it to binary. In binary computer, normally electronic computing, there are two values 1 or ON and 0 or OFF. A ternary computer using fiber optics could use three values: 0 or OFF, 1 or low, 2 or high. This future potential has also been remarked by certain companies as Hypres which is actively engaged in ternary computing. IBM also reports infrequently on ternary computing topics (in its papers), but it is not actively engaged in it.

      In reference to your comment about floating point, the argument he makes is that it is not something to be taken lightly. I don't know about speed anymore on modern computers. It used to be the case that executing floating point operations was much more costly than integers. Something tells me that this is still probably the case, though I am certainly not an expert on chip design. RISC units IIRC do addition and subtraction in substitution for multiplication and division because they can do so much faster. I imagine the risc-like guts of AMD and intel chips to be pretty similar. Any evidence to back up your point?

    4. Re:This guy is my new hero.... by ZosX · · Score: 1

      thanks. I just upgraded to a pretty sweet camera and the adventure continues. as soon as I get a pro account on flikr I'll start dumping some of the much better shots I've been taking lately. for what its worth everything you see (except for some west coast pics) were shot with a powershot 590is. I dropped mine (again) and finally broke it, but it was a great little pocket camera with full manual controls for like $100. They quit making them, so I guess get one while they last. The newer A1000 or whatever is automatic only which is too bad. I just got a Panasonic FZ28 and its like 5x the camera that my canon was for really cheap and definitely is starting to approach DSLR territory in image quality. I'll have some new pics up soon, I promise. I already got 100 or so keepers in two weeks. :)

    5. Re:This guy is my new hero.... by Anonymous Coward · · Score: 0

      > RISC units IIRC do addition and subtraction in substitution for multiplication and division because they can do so much faster.

      AFAIK, all modern computers do integer multiplication and division using addition, subtraction, and shifts in hardware. That way, multiplying any two 32-bit integers takes at most 32 steps. (Pure addition would usually be worse; consider multiplying 1234 * 1234 using only addition: it'd take you 1234 steps). Bit shifting gives easy multiplication/division by powers of 2, so in a way the hardware is doing it kind of like the way we do long multiplication/division by hand.

    6. Re:This guy is my new hero.... by evilWurst · · Score: 1

      > There were some great ideas back in the days when computers were in there infancy and a lot of them have been abandoned for the most part. Like trinary computing for instance. The building blocks of the computers that you see today were partially designed because of technological limitations at the time. The mechanical underpinnings of the first computers are still present today. I don't care if I'm really wrong about this point (I've been wrong before), but I think computing really needs to transcend a system based on 0s and 1s.

      The short answer is that you're probably wrong on this point, but only due to lack of information. I probably won't do much better trying to respond. Trying to boil down a few semesters of higher level CS classes here: essentially, once you get to studying the fundamentals of computation, it turns out that all the really good methods are equally powerful. Powerful in terms of what kind of problems they can and can't solve.

      So in practical terms, what happens is that the hardware that gets produced does its thing based on whatever was more efficient from the stuff the materials science and electrical engineering people figure out. If they figure out a way to get three states working cheaper than two, then yay, we get the benefit of the resulting lower prices or incremental linear speedup - but our algorithms will still be doing things the same way.

    7. Re:This guy is my new hero.... by Sycraft-fu · · Score: 1

      Go have a look at something simple like SiSoft Sandra benchmarks. You'll notice that the processors do about the same in terms of integer and floating point calculations. While it may well require more silicon to achieve that floating point performance, the processors have it so it isn't an issue.

      This isn't to say don't use integers when needed. They perform fine there and now with 64-bit chips you can store larger values in integer registers. However if fractional results are needed, then use the FPU. Don't waste your time and computer cycles trying to design an algorithm that hacks it in to an integer. There's no reason.

      Now I'm not saying this is the case on all devices. There are embedded CPUs that lack FPUs. Ok in that case you don't want to use floating point numbers as the calculations will have to be done by a slow math library. However for desktop CPUs, Intel and AMD CPUs, they scream at floating point performance.

      Also there's plenty of situations where floating point is important. If you have a situation where you have a wide range and you need to maintain precision over the whole range, you need to operate in floating point. A good example would be graphics shaders. If you do it fixed point, rounding errors add up and produce visible artifacts.

      So the real answer is use fixed point when it makes sense, use floating point when it makes sense. Anyone who has this "One or the other is evil," mentality is a zealot, and really doesn't have a good understanding of how modern CPUs work.

  13. And what makes you think that LISP is interpreted? by PaulBu · · Score: 4, Informative

    It can be, but any decent production implementation is compiled to native machine codes -- it just includes compiler (and usually pretty fancy optimizing one!) built into the image and always available.

    Try running, say, SBCL one day before spreading misunderstandings...

    Paul B.

  14. Re:And what makes you think that LISP is interpret by PaulBu · · Score: 0

    Sorry, was not clear -- had to proof-read. Not only the implementation is compiled (obviously), but everything you (load) or type into the REPL prompt is compiled to native code as well before being executed.

    Paul B.

  15. oblig by olivier69 · · Score: 5, Funny

    In speed and elegance, perhaps.

    So you agree to the fact that emacs is faster and more elegant than vi, right ? You agree ?

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

      So you agree to the fact that emacs is faster and more elegant than vi, right ? You agree ?

      NO! I'll never stop using the devil's editor!

    2. Re:oblig by Anonymous Coward · · Score: 0

      What? It's the editor of the beast (six hundred, three score, and six) , not the devil.

  16. Is httpd performance in the userspace code? by jonaskoelker · · Score: 4, Interesting

    Based on my theoretical understanding of how computers work, I though HTTP daemon performance depended mostly on

    • I/O performance, much of which is controlled by the kernel (in particular the file system).
    • A good caching strategy (to minimize I/O), again done by the kernel.
    • Good networking performance, controlled by the networking stack in the kernel.
    • Database performance, controlled by the RMS-DB, BDSM(R) or whatever it is.
    • Process spawing speed (for CGI), again controlled by the kernel.

    Would someone care to correct me?

    Note that TFA (well, the slideshow) measures performance in requests per second. That's a very useful measure, but it's compared to Ruby (Mongrel?) and PHP (Apache?). I'm not sure what that comparison means. Does Apache not support lisp, or only as CGI?

    Is there something stopping Apache from being sped up? Is he measuring the performance of LISP, or the performance of a HTTP daemon?

    I'm a bit confused...

    1. Re:Is httpd performance in the userspace code? by asdf7890 · · Score: 1

      The web server can be a significant factor in performance then the server is under load, as winessed by Lighttpd being significantly faster then Apache under some workloads and configuration. There are many things the web server can have some affect on (its own memory use, management of fcgi processes, and so forth)

      You say that "requests per second" is a useful measure but without the information you yourself suggest is missing I would not agree that it is. There is a vast range of difference between requests that just pull a single static file and requests that his a script interpreter which in turn needs to hit a database... Even if they state that the requests were for PHP output there are a variety of ways PHP can be called and that will affect performance (at least four: module [most common under Apache], CGI, FCGI [most common under lighttpd], ISAPI [under IIS]). Unless otherwise stated I assume that req/sec measures are referring to requests for static files though any benchmark like that which doesn't describe the environment used in some detail is essentially meaningless.

    2. Re:Is httpd performance in the userspace code? by DougWebb · · Score: 1

      Is there something stopping Apache from being sped up?

      Apache is designed to be extremely modular; every request goes through a series of hooks which call out to modules to give them a chance to do something with the request before it's passed onto the next module on the hook or the next hook on the chain. While this makes Apache incredibly flexible and very easy to extend, it also slows down the request processing.

      A less flexible design can be made to perform faster, because it doesn't have to do all of the checking needed to determine how to handle the request. Fewer options == Fewer checks. For my company's web application, I wrote a custom HTTP server in Perl years ago which is still in use today. It handles our application and static files, and that's it. It performs as well as a well-designed Apache/mod_perl application, and better than a FastCGI application. That's pretty good for something that has been virtually unchanged since well before mod_perl existed.

    3. Re:Is httpd performance in the userspace code? by Vellmont · · Score: 1

      I'm not a performance guru, but if you're talking about static HTML pages I'd guess you're correct. If you're talking about a dynamically generated page though, the underlying code that generates the page plays a much larger role in performance than does the underlying architecture you're describing.

      The article referenced being fast at serving up dynamic content. That means it's being compared to things like PHP, perl, Java, etc. It's also about "small" (which isn't defined). But I'd guess the languages I just mentioned wouldn't be included in "small".

      --
      AccountKiller
  17. Re:Attention Pooftahs and Frenchies by julesh · · Score: 3, Informative

    Today is Memorial Day in the United States of America. We would appreciate you folks taking some time to reflect on our servicemen who gave their lives saving your asses in WW I and II.

    We do that on Nov 11, thanks. I don't see why we need to adopt your dates for the purpose.

  18. Re:And what makes you think that LISP is interpret by jonaskoelker · · Score: 1

    Try running, say, SBCL [...] Paul B.

    Hi Paul. Is the B short for "Braham"? ;-)

  19. Real programmers.... by Anonymous Coward · · Score: 0

    ... use a keyboard with 3 keys. 1, 0, enter. Assembly is for n00bs!

  20. But C is more readable by klapaucjusz · · Score: 2, Funny
    1. Re:But C is more readable by Anonymous Coward · · Score: 0

      It's called a function.

      Honestly, sure some things are ugly in C [linked lists and the sort for instance] which is why a COMPETENT programmer would factor those out into functions which they would test once and use many times.

      That persons code you linked to is a prime example of something that could have been abstracted away with proper code factoring.

      In short, the person is a shitty C coder [or their example is just shitty].

  21. Yeah right. by stonecypher · · Score: 4, Insightful

    Of course, this guy didn't benchmark against any modern performance kings, such as Nginx, YAWS, htstub or LightStreamer.

    There is no reason to believe this is the world's fastest webserver, and I'm sure as hell not holding my breath.

    --
    StoneCypher is Full of BS
    1. Re:Yeah right. by Anonymous Coward · · Score: 0

      You think nginx is better than apache because of it's speed ? First of all, delivering non static content apache is faster in many cases either way, yet nginx is better because of the memory usage. Who cares about a few miliseconds in loading time, when it can handle a dozen more requests on the same hardware.

    2. Re:Yeah right. by osu-neko · · Score: 1

      Of course, this guy didn't benchmark against any modern performance kings, such as Nginx, YAWS, htstub or LightStreamer.

      None of these are frameworks for small dynamic web content, so it wouldn't make sense to benchmark against them

      There is no reason to believe this is the world's fastest webserver, and I'm sure as hell not holding my breath.

      No one claimed it was the world's fastest webserver. Try reading entire sentences, rather than grabbing a phrase or two out of the middle of them.

      --
      "Convictions are more dangerous enemies of truth than lies."
    3. Re:Yeah right. by TheRaven64 · · Score: 1

      What part of 'for dynamic content' did you miss? The web servers you list are performance kings for serving static pages.

      --
      I am TheRaven on Soylent News
    4. Re:Yeah right. by ionix5891 · · Score: 0, Flamebait

      you sir are an idiot

    5. Re:Yeah right. by stonecypher · · Score: 1

      Of those four, only Nginx is for static content. I cannot imagine why you'd think otherwise of YAWS, htstub or lightstreamer.

      --
      StoneCypher is Full of BS
  22. Re:World's "Fastest" Small Web Server Released, Ba by pmc · · Score: 3, Informative

    I think there is an implied "still in use" in the statement - otherwise this is a list - http://en.wikipedia.org/wiki/Timeline_of_programming_languages suggests there are older ones still, and Lisp wasn't even third by any stretch.

  23. Wrong on epoll and AIO by edivad · · Score: 1

    Since the advent of eventfd(), you can wait for disk AIO (via KAIO), using epoll_wait().

  24. Yeah right... by McNihil · · Score: 1

    not that I want to pee all over anybodies accomplishments BUT when I see a pure implementation of BSD sockets using pure LISP and IT beats the C version then and only then will I ACK that SYN statement.

  25. Re:And what makes you think that LISP is interpret by klapaucjusz · · Score: 2, Insightful

    [Lisp] can be [interpreted]

    Actually, Common Lisp cannot be implemented as a pure interpreter -- there are a few features of the language that you cannot implement without performing a pass over each function.

    (Scheme, the other dominant dialect of Lisp, can be implemented as a pure interpreter, a pure compiler, or a hybrid design.)

  26. Re:Attention Pooftahs and Frenchies by Morphine007 · · Score: 3, Interesting
    Hi, I'm from Canada. We're those soft-spoken guys to the North of you who were used as shock troops in both those wars you mention. We did the job when no one else could.

    Your current soldiers are solid. Your previous soldiers were solid. This isn't a pissing contest, but when it comes to having historically solid troops I think we, at least, have earned the right to reflect on the sacrifices of our respective troops on different days *. Yours on your day, and mine on my day. Which is to say, we know it's memorial day. Your soldiers are and have been heroes, but keep your holiday to yourselves. Just as the rest of us keep ours to ourselves.

    * - it's worth noting (though I can't find the citation) that the method by which the cdns held kapyong against the 3-5:1 odds was by calling down artillery on their own position

  27. Thufferin' thuckitaz by AnalPerfume · · Score: 1

    Isn't LISP an ideal companion to Python? Thnakes in cartoons talk with lithps after all, and Snagglepuss even. LISP maybe eethy to read but it's not easy to thay, that'th why they call it a lithp.

    1. Re:Thufferin' thuckitaz by K.+S.+Kyosuke · · Score: 1

      I realize you are just being silly here, but there is actually *is* already a Python embedded in today's most popular Lisp implementation, SBCL. The Lisp compiler in SBCL and its predecessor (CMUCL) was named Python back in 1985. That said, a Lisp-Python bridge, which is much more interesting, has already been written as well.

      --
      Ezekiel 23:20
  28. Oh this makes me happy... by Onyma · · Score: 2, Interesting

    I first learned LISP using the watered down version included in AutoCAD while writing huge customization projects in the 80's. I loved the language so much I dove into it full force and enjoyed it thoroughly. To me it was so inherently elegant I wanted to use it everywhere. Obviously however making a living meant most of us had to focus our energies elsewhere but something like this makes me all giddy again. I think I have some playing to do!

    --
    Play me online? Well you know that I'll beat you. If I ever meet you I'll "/sbin/shutdown -h now" you. -Weird Al, kinda.
  29. His example blog is already Slashdotted... by macraig · · Score: 5, Funny

    ... so I guess it's not fast enough.

    1. Re:His example blog is already Slashdotted... by Anonymous Coward · · Score: 0

      Actually the link given doesn't seem to be using lisp as a server. There error page gives the following :

      Apache/2.2.4 (Ubuntu) mod_fastcgi/2.4.2 PHP/5.2.3-1ubuntu6.5 Server at john.freml.in Port 80

    2. Re:His example blog is already Slashdotted... by macraig · · Score: 2, Funny

      I guess he's not talking with a lisp after all, then, he's just lying through clenched teeth.

    3. Re:His example blog is already Slashdotted... by AlXtreme · · Score: 1


      Apache/2.2.4 (Ubuntu) mod_fastcgi/2.4.2 PHP/5.2.3-1ubuntu6.5 Server at john.freml.in Port 80

      Whoops...

      --
      This sig is intentionally left blank
    4. Re:His example blog is already Slashdotted... by Anonymous Coward · · Score: 0

      ... so I guess it's not fast enough.

      obligatory "it's a hardware problem"

  30. Re:Attention Pooftahs and Frenchies by osu-neko · · Score: 4, Funny

    We do that on Nov 11, thanks. I don't see why we need to adopt your dates for the purpose.

    But... but... Nov. 11th is a horrible date for outdoor grilling! That would ruin the holiday entirely. I don't think you really grasp what Memorial Day is all about...

    --
    "Convictions are more dangerous enemies of truth than lies."
  31. You can also do that in C by rbarreira · · Score: 1

    C (and even assembly) can't realize that the same inputs to a routine always cause the same output, and therefore cache the return value and just return it (not without a lot of buggy, custom code anyway). (I'm not saying Java/C# DO this, they may--I understand they were working on it... But just trying to give you an idea of what CAN be done)

    You could also easily implement that in C. Of course it would only apply to purely functional C functions, i.e. ones which behavior only depends on their arguments, and that don't have any side effects. But that restriction would also apply to the Java case.

    --

    The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
  32. Web server versus web framework? by Anonymous Coward · · Score: 0

    This is a terrible summary and for a few minutes I thought the submitter was a complete moron.

    Apparently this thing is both a web server and web framework. It also looks to be nothing more than an experiment currently.

    It might be faster than Rails but I seriously doubt that it is faster to develop for than Rails. Make a framework that makes DEVELOPMENT easy and solid, THEN make it fast. If the goal of Rails was to be the fastest web framework then it probably WOULD BE.

    1. Re:Web server versus web framework? by FishWithAHammer · · Score: 1

      Make a framework that makes DEVELOPMENT easy and solid, THEN make it fast.

      Maybe you should tell the Rails people this. Right now, they do neither.

      If the goal of Rails was to be the fastest web framework then it probably WOULD BE.

      Erm...no. For reasons so often repeated that it shocks me that you'd try to trot out this crap. Rails will never even be close to the "fastest" because its architecture is mouthbreathingly stupid and it is based on a comparatively slow language.

      --
      "You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
    2. Re:Web server versus web framework? by An+Onerous+Coward · · Score: 1

      As a mostly-satisfied Rails developer, I have two questions:

      1) Could you link to something that explains the stupidity of the Rails architecture?

      2) So, what do you use? And are you happy with it?

      --

      You want the truthiness? You can't handle the truthiness!

  33. Ediware? by Anonymous Coward · · Score: 0

    (a) "Lisp". all uppercase "LISP" went out with flares. Sheesh.

    (b) How does it compare to Edi Weitz' excellent http://www.weitz.de/hunchentoot/ ?

  34. Re:World's "Fastest" Small Web Server Released, Ba by Deanalator · · Score: 1

    Plankalkul was first implemented in 2000, so I think it missed the game by a long shot. If we are talking about pretend programming languages, Ada's language still beats out this guy by over 100 years.

  35. Re:And what makes you think that LISP is interpret by PaulBu · · Score: 1

    Nope, different guy! But I do get your joke... ;-)

    Paul B.

  36. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 0

    You say that like speaking German is a bad thing. It's certainly a hell of a lot better language than that bastardisation of English you use over there.

  37. Re:And what makes you think that LISP is interpret by mwlewis · · Score: 1

    I really don't know much about LISP, but I'm having a hard time understanding why "performing a pass over each function" rules out being a "pure interpreter." Maybe we just have different definitions of what that means. Could you please clarify?

    --
    JOIN US FOR PONG!
  38. Parenting^H^H^Hhesis by dargaud · · Score: 1

    One thing( I could never wrap my head around( is that functional languages consider that functions have no side effect.) Which is all fine( for mathematics), but in the real world( everything has a side effect: printf( is a side effect). Serving some html( is a side effect). Anything (that has to do with I/O is a side effect)). It breaks( the whole concept), so we might as well( keep using( a language that doesn't( overburden itself) with insanely( obnoxious and contrived) theoretical considerations))) (that it will break anyway), like...) C

    --
    Non-Linux Penguins ?
    1. Re:Parenting^H^H^Hhesis by msuarezalvarez · · Score: 1

      One thing( I could never wrap my head around( is that functional languages consider that functions have no side effect.) Which is all fine( for mathematics), but in the real world( everything has a side effect: printf( is a side effect).

      This only shows you are ignorant about the way purely functional languages deal with "the real world"...

      Do buy a textbook on, say, Haskell. Read it. Play with the thing a bit. Then start to comment about things.

    2. Re:Parenting^H^H^Hhesis by Anonymous Coward · · Score: 0

      Except Lisp doesn't enforce that.

      (defun f (x y)
          (if (> x y)
                (print x)
                (print y)))

    3. Re:Parenting^H^H^Hhesis by K.+S.+Kyosuke · · Score: 1

      He can even try before he buys.

      --
      Ezekiel 23:20
    4. Re:Parenting^H^H^Hhesis by Tiro · · Score: 1

      Programs have end goals which would fall under your definition of side effects. When I'm abstracting and simplifying my constituent algorithms, I use functional style. Then, those functions make a lot more sense in the context of the main program flow. Different styles for different purposes.

    5. Re:Parenting^H^H^Hhesis by Anonymous Coward · · Score: 0

      You never tried Haskell, did you ? Haskell (or Clean) encode in the type system the purity of your functions : you literally can't do side effects in your Haskell functions. To do impure programming in Haskell you have to use the IO monad, which is a one-way monad (once entered you can't get out, side effects can't escape). A Haskell program is typically build of two part : a portion of pure code (see XMonad, a WM in Haskell to see that even in apparently very IO oriented programs the pure code constitute the major part) and a portion of IO code to interact with the world and drive the evaluation.

      --
      Jedai

  39. Re:And what makes you think that LISP is interpret by PaulBu · · Score: 1

    Interesting, did not know that... What would be an example? I thought that some other Free CL implementations are interpreters, but I might be confused, CLISP does compile to bytecodes, and GCL uses gcc...

    Paul B.

  40. Re:Attention Pooftahs and Frenchies by Whalou · · Score: 2, Informative
    From http://www.kvacanada.com/stories_rskap'yong.htm

    About 1 a.m. April 25, a Dog Company platoon was attacked from three sides by large numbers of enemy troops. Two Patricias manning a Vickers machine-gun where killed. Waves of Chinese spilled into the company area. It was hand-to-hand-fight-for-your-life combat. Dog Company was on the verge of being overrun. The company commander, Capt. Wally Mills, requested that artillery be fired on his own positions. The New Zealand gunners obliged. The defenders hugged the bottom of their trenches while artillery shells roared in overhead. The shells scoured everything above ground level, driving off the Chinese. But they returned. More artillery fire followed. 2300 rounds hammered Dog Company positions.

    This web site was cited in the Wikipedia artical posted by the parent.

    --
    English is not this .sig mother tongue...
  41. Re:World's "Fastest" Small Web Server Released, Ba by osu-neko · · Score: 1

    ... the first compiler for it was implemented in 1998.

    Plankalkul may have been conceived first, but generally, the age of something is measured from the date of birth, not the date of conception.

    --
    "Convictions are more dangerous enemies of truth than lies."
  42. Re:World's "Fastest" Small Web Server Released, Ba by osu-neko · · Score: 1

    Depends on your definition of "high level". Most of the ones on that list older than LISP and Fortran wouldn't qualify...

    --
    "Convictions are more dangerous enemies of truth than lies."
  43. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 1, Insightful

    Well, I'll celebrate memorial day when the Americans start celebrating their liberation from the British by the French on October 19th.

  44. Re:Attention Pooftahs and Frenchies by Morphine007 · · Score: 1

    Awesome, thanks =)

    It's a story that is still (at least 5 years ago when I went through) recounted in infantry officer training for the Canadian military.

  45. Written in Lisp? by 93+Escort+Wagon · · Score: 1

    Okay, it may be the fastest web server in the world - and it's dependent on the oldest programmers in the world. With most web server applications, you have to worry about computer viruses - with this one, you have to worry about Alzheimer's.

    --
    #DeleteChrome
    1. Re:Written in Lisp? by Anonymous Coward · · Score: 0

      The dude is a legend, and in his mid-twenties. It's a language of computer scientists I suppose. I loved writing in scheme.

  46. Don't knock LISP by LunarEffect · · Score: 1

    My Informatics Professor swears by it. He uses it for absolutely everything. I was shocked at first, but as the XKCD comic says, it does have a kind of timeless beauty to it =)

    1. Re:Don't knock LISP by OrangeTide · · Score: 1

      LISP is very good.
      But I never touch the stuff because it's easier to get a job programming C, at least around here. And frankly my C skills are much better than my LISP skills.

      --
      “Common sense is not so common.” — Voltaire
  47. Error Message by Tablizer · · Score: 2, Funny

    It has one and only one error message: "Missing Parenthesis" ;-)

    1. Re:Error Message by shutdown+-p+now · · Score: 1

      It has one and only one error message: "Missing Parenthesis" ;-)

      You've missed the other one, actually. It says:

      "Extra parenthesis".

      Rumor it is that sometimes it also just prints out 42, seemingly randomly...

    2. Re:Error Message by Tablizer · · Score: 1

      You've missed the other one, actually. It says: "Extra parenthesis".

      Okay, "incorrect parentheses nesting" should cover both. The compiler cannot really know for sure that it's "extra" anyhow, or missing the starter.
         

  48. Re:"you can't be faster than C" by Anonymous Coward · · Score: 0

    That all depends on the compilers at hand. Without really advanced code analysis, a C compiler cannot generate code that uses the carry bit, cache prefetch instructions, etc.

    Because of that, a higher-level language with built-in higher-level constructs such as 256-bit integers might beat a C compiler in the speed game.

  49. He's also right by Sycraft-fu · · Score: 5, Insightful

    Reason being is that C is the closest high level language to how a processor actually operates. A lot of people get confused, or perhaps never really know how a CPU actually works and that no matter what language you code in, it all gets translated in to machine language in the end.

    Now what that means is that there are certain things that, while convenient for humans, have nothing to do with how the processor actually thinks. A good example would be newer replacements for pointers. A lot of people hate pointers, they claim, correctly, that pointers are confusing, and that you can easily cause problems with them. That is all true, however it is also how the CPU actually thinks. The CPU doesn't have advanced concepts of references and of garbage collection and so on. The CPU has data in memory, and pointers to the location of that data. It doesn't even have data types. The data is just binary data. You can store a string, and then run calculations on it using the FPU. Granted you'll get garbage as a result, but there's nothing stopping you from doing it, the CPU has no idea what your data is.

    So, the upshot of this is that C is very close to the bare metal of how the system works. Thus if you are good with it, you can produce extremely efficient code. The higher level stuff may be nice, but it all slows things down. When you have a managed language that takes care of all the nasty stuff for you, well it is spending CPU cycles doing that. Now the tradeoff is quite often worth it, since CPUs have loads of power and maintainability of code is important, but don't trick yourself in to thinking it is more efficient.

    You have to remember that no matter what, there is one and only one way that the machine actually thinks, one way it actually processes information. All the nifty high level programming shit is just to make life easier for the programmers. That's wonderful, but it doesn't give you the most optimized code. Of the high level languages, C retains that crown, and likely always will, because it is the closest to how a CPU actually works. I've seen the joke that "C is a language with all the speed of assembly and all the ease of use of assembly!" There's some truth to that.

    So I have to agree with the grandparent. If the LISP heads think LISP is faster than C, they are kidding themselves. I'm not saying a good LISP program can't be faster than a bad C program, but if you have equal skill in optimization, sorry C will win out because in the end it will generate more efficient machine code and that's all that matters. All the theory of different programming paradigms in the world isn't relevant to how the CPU is actually going to do things.

    1. Re:He's also right by TheDarkMaster · · Score: 2, Insightful

      Where is my mod points when I need then... This guy needs a +1 Insightful

      --
      Religion: The greatest weapon of mass destruction of all time
    2. Re:He's also right by Anonymous Coward · · Score: 4, Informative

      C is not how a modern processor thinks, with super-scalar instruction issue, cache and pre-fetch memory controls, and speculative branch prediction. In the end, even the C community splits into camps that let the optimizer do everything, versus embed some hand-written assembly or equivalent "machine intrinsics" routines in the middle of their normal C code. In both cases, non-trivial amounts of profiling and reverse-engineering are often needed to coax an appropriate machine code stream into existence, and this machine code is decidedly not how the developers usually think.

      The choice of language is not so significant really. You can find Lisp dialects that efficiently use native machine types and have little runtime cost due to having weak type systems (just like C) where casting is easy and the responsibility for crazy results lives with the programmer and the limited ability of the compiler to check some static cases. These dialects will run imperative code quite well, e.g. if you transliterated typical C procedures into equivalent Lisp procedures, you'd get similar performance. Ironically, these systems aren't as fast when you write very high-level or functional Lisp, because those sorts of programs rely on a more elaborate optimization and runtime support layer, e.g. to optimize away recursive function call overheads or frequent allocation and destruction of temporary data like lists. This kind of code also doesn't work well in C, so the programmer has to perform these optimizations at the source level, by writing loops instead of recursion and making use of stack variables and static data structures instead of making many malloc/free calls in inner-loops, etc.

      The main difference is the presumed runtime system for the language, the compilation goals, and the core language libraries. This includes things like whether you have garbage collection or explicit memory management, how you compile (whole program versus treating every function/procedure as an ABI symbol), high-level IO abstractions or low-level register (or memory-mapped) IO and interrupt events, etc.

      If you're interested in this stuff, you might learn something from reading about PreScheme, which was a lisp dialect designed to allow the runtime system for a full Scheme (lisp dialect) to be written in a more limited Scheme-like language. This is much like the core bits of an OS kernel like Linux are written in carefully controlled subsets of C that do not presume the existence of an underlying runtime environment nor the standard C library.

      In reality, many of the compiler and runtime techniques applied to a simple language like lisp could be applied to a C implementation as well. It's really a cultural rather than technical issue which prevents there being C environments that skip the traditional, naive compile and link strategy used in POSIX and UNIX ABIs.

    3. Re:He's also right by Anonymous Coward · · Score: 0

      C also lacks several important features for optimization, such as static typing, or general reasoning about memory and parallelism. The CPU executes instructions, oftentimes in parallel pipelines, using an instruction cache and branch prediction - none of which are modelled in the C language.

      If you knew even half as about language implementations as you claim to, you'd know that the C language holds it's speed crown simply because it has attracted an _enormous_ amount of research into optimizing compilers, largely because the way C works _isn't_ the way the CPU works.

    4. Re:He's also right by The_Wilschon · · Score: 5, Informative

      You forget about compilers. LISP gets compiled (by most implementations), too. All the "nifty high level programming shit" can, and sometimes does, if you have a good enough compiler, get compiled away. Furthermore, the "nifty high level programming shit" provides a whole lot more information to the compiler, allowing it to do much more aggressive optimizations because it can prove that they are safe. If somebody comes up with a slick new optimization technique, I don't have to rewrite my LISP code, I just implement it in the compiler. You'd have to go back through every line of C code you've ever written in order to implement it. If somebody gives you a radically different CPU architecture, the C code that is so wonderfully optimized for one CPU will run dog slow. You can reoptimize it for the new arch, but then it will run slow on the old one. With a good LISP compiler, the same code gets optimizations that are appropriate for each arch.

      Check out Stalin, SBCL, and http://www.cs.indiana.edu/~jsobel/c455-c511.updated.txt. You might be surprised at what you find.

      --
      SIGSEGV caught, terminating

      wait... not that kind of sig.
    5. Re:He's also right by Skinkie · · Score: 2, Informative

      And that is the point LISP guy wants to make iff I have a LISP compiler that in general optimises better than the coding structure a C programmer takes, it will be faster because you could heavily optimise the LISP compiler. In the same ballpark are Haskell (and maybe in the future Python) iff their compilers generate better structures because the task is better formally defined. It could generate the optimal structure for the problem. Maybe more optimal than a human would design it. Today: no.

      --
      Support Eachother, Copy Dutch Property!
    6. Re:He's also right by Anonymous Coward · · Score: 0

      You're right.

      ...unless of course we had a modern day LISP Machine. In which case you could switch one language for the other and still be right. :P

    7. Re:He's also right by Sectrish · · Score: 5, Insightful

      I fully agree with your post (I prefer C over most other languages myself for some weird reason, but if it n eeds to be made *right now*, I'll use Python/Perl/Bash/...).

      However, there is an addendum I'd like to make here:

      Some programming languages force you to think in ways that are actually beneficial to the speed of your code, and can outpace the "normal" C program significantly.

      For example, a few months ago I was forced to write something concerning an AI algorithm in Prolog. Now, I was cursing and cursing at it, because the constraint solver built into the prolog compiler was so goddamn restrictive, but that's how constraint solving works. Every time I was thinking to myself: "if I'd have been allowed to build this in C, it would be done yesterday, and probably be faster to boot!"

      But when I ended up finishing it and running it, it was blindingly fast, and I queried my professor about it. He told me that another student some time ago was thinking the same thing as me, and actually made a C variant. It ran 4x as slow as the prolog equivalent even after spending quite some time optimizing (interchanging algorithms and even looking at the assembler code, he told me).

      Then he told me what was causing this discrepancy, as I had always thought that C was the end all be all of performance. It was the restrictive nature of the prolog solver that caused me to put more brain power into the problem, and as such shift work from the computer to the human. Because those same restrictions allowed lots and lots of optimisations (aliasing comes to mind).

    8. Re:He's also right by Anonymous Coward · · Score: 0

      You might have a point. But do you really think that references are an advanced concept compared to pointers? Really?

      One should note that whilst it is possible to compile a program to target different architectures it is seldom done. So most of the binaries out there can be made faster. This would not be the case if a jit compiler where to be used.

      I think an assembler programmer would use the same argument as you about C but be a bit more humble. I don't really know anyone that can constantly write better assembler than a C compiler, parts maybe, but not complete programs.

      What I am trying to say is that C is the king. But who knows what will happen 50 years from now?

    9. Re:He's also right by amn108 · · Score: 4, Interesting

      I'll start with the good things. First of all, I like your style of writing - clear, precise and on point (of your choosing). Second, you explain quite well on the scenery here.

      Now, to the bad things. I can almost bet you either are not a day-to-day programmer, as opposed to casually writing simple bits of code in C perhaps, or you just do not know either a lot of computing history or latest developments in compilers and technologies in general. Maybe you write niche software and are not interested in these developments, I do not know, but I think it is a bit odd you give such a good and knowledgeable read, yet completely (in my humble opinion) miss the facts overall.

      Machines are different too. There is RISC, there is ZISC, there is VLIW and the CISC/RISC hybrid that modern CPUs mostly are. These days we are also starting to think how we can utilize vector processors, which to gamers are quite familiar as their video cards. Everyone has one, either they know it or not, nowadays they install a 500 mFlops graphics card in PCs in use by hotel receptionists.

      So, C was designed to go close to the metal yes, but since metal is different, C may shoot or miss depending on the architecture too.

      What is far more important, given that today we still use mostly the same instruction set we used when C was invented, is the fact that you are absolutely mistaken if you think high-level languages will not approach C. You overestimate hand-optimization and underestimate modern compilers. It is illogical to assume that a person IN FRONT of the computer terminal will know and benefit from knowing how a program of his writing may be optimized. It is the computer itself, that, based on sufficiently well developed compiler, has the potential to optimize code. The mere fact that in practice it is not always so, is because the field is immature, but not to worry, rapid developments are made.

      Also, things like static typing, static code analysis and other logical solutions absolutely negate any benefit C may have. Also, I am surprised you compare garbage collecting to C, given how programs developed with C still need occasionally, depending on their domain, allocate objects on the heap, and how most virtual machines allocate values on the stack under the hood, even those with garbage collector.

      Anyways, to cut short here, and perhaps give you a chance to explain and ridicule me :-), I will just say I find your comparison of C to say LISP is grossly oversimplified, and does not work on me. It is in fact programming paradigms that have liberated compiler writers to write increasingly effective compilers. Spend some time reading on theory of computation on Wikipedia for instance, it has given me a whole new look on the state of the art. Bottomline is, teaching computers how to translate human typed grammar more efficiently into their program execution machine is getting much cheaper and much more fruitful than spending time or energy hand-writing C code, and I am not talking about the "compromise of man hours", I am saying both LISP and C programs being equally 'good', they can be equally fast, especially depending on the LISP compiler.

      Thank you for your attention, I know how precious it is here on Internetlands.

    10. Re:He's also right by Anonymous Coward · · Score: 0

      This isn't always true - a higher level language with different semantics can actually give an optimiser more flexibility, simply because it can make more assumptions. An optimiser can't really assume that much about pointers, because all sorts of weird uses and behaviours are valid - an object reference gives the optimiser a great deal more room to move. This will be especially important if automatic parallelisation of programs ever becomes possible...

      There's also always the fact that development time takes much much longer in C than high levels languages, so given a fixed amount of development time, as there always is in practice, programming in a different languages gives you far more time to optimise at the level of algorithms or architecture, or to optimise critical sections. If you halve the amount of development time you spend on the 90% of the code that isn't speed critical, that gives you way more time to optimise the 10% that is.

    11. Re:He's also right by setagllib · · Score: 3, Interesting

      C also lacks several important features for optimization, such as static typing,

      Surely you jest. C has weak static typing, but it's static typing all the same, and any " + " you see in C code becomes a specific instruction once compiled. Just because that + could be for pointers, doubles or ints doesn't mean it's not static once read in context.

      The weakness comes from standard C accepting almost any implicit conversion and cast, which is trivially changed to somewhat strong (but not runtime-enforced) typing by using compiler warnings and errors.

      or general reasoning about memory and parallelism.

      Parallelism remains fastest in C, especially in OS kernels where the cost of synchronization primitives is close to a bare minimum. If you have a modern compiler that can distinguish vectorisation from its own ass, you'll get healthy use of parallel code pipelines too.

      The CPU executes instructions, oftentimes in parallel pipelines, using an instruction cache and branch prediction - none of which are modelled in the C language.

      None of which has to be. If you need that kind of performance, you have two options, both with free software:

      a) Embed simple non-standard statements to communicate your branch prediction beliefs

      b) Use profile-guided optimisation to automatically sample real branching statistics, and recompile based on those

      Either way you end up with superior branch prediction performance. Certainly far far superior to what you'd get with LISP or Python.

      If you knew even half as about language implementations as you claim to, you'd know that the C language holds it's speed crown simply because it has attracted an _enormous_ amount of research into optimizing compilers, largely because the way C works _isn't_ the way the CPU works.

      Ok, so what non-assembly language do you propose that does work the way a CPU works? C is the closest we have, and with modern compilers it's way faster than any other usable language. The effort of writing C is far lower than that of writing assembly, and you generally get better performance unless you know specific SIMD/MIMD instructions to replace a loop or two.

      --
      Sam ty sig.
    12. Re:He's also right by Anonymous Coward · · Score: 2, Interesting

      Surely you jest. C has weak static typing, but it's static typing all the same, and any " + " you see in C code becomes a specific instruction once compiled. Just because that + could be for pointers, doubles or ints doesn't mean it's not static once read in context.

      That's great. You're still missing all the nice things that make a static type system nice. There are functional languages with Turing complete static type systems. Indeed, the nice thing about that is that every static type deduction is equivalent to a constructive proof quantifying over type elements. Can C even define a type as a first-class object? Maybe with macros, but the average C programmer is scared to death of higher order quantification. They seem to want to tell the computer exactly what to do, step by step, instead of letting it figure it out itself at compile time.

      Heck, even C++'s is Turing complete, via templates.

    13. Re:He's also right by QuantumG · · Score: 0, Troll

      ha. LISP is pre-parsed.. as in, you're programming in the god damn intermediate language. () does not a syntax make.

      --
      How we know is more important than what we know.
    14. Re:He's also right by shutdown+-p+now · · Score: 3, Interesting

      So I have to agree with the grandparent. If the LISP heads think LISP is faster than C, they are kidding themselves. I'm not saying a good LISP program can't be faster than a bad C program, but if you have equal skill in optimization, sorry C will win out because in the end it will generate more efficient machine code and that's all that matters. All the theory of different programming paradigms in the world isn't relevant to how the CPU is actually going to do things.

      It's true that any given piece of code can be written to perform faster (or at least not any slower) in C then in Lisp, Java, C#, or whatever your favorite high-level programming language is.
      However, this doesn't mean that applications written in idiomatic, well-written C are necessarily faster than some-other-language. Why? Well, here's a very simple example.

      Let's say you need to sort some stuff in an array. In C, you can hand-code a quicksort or a merge sort inline that will blow anything else out of the water... if you're only doing it once. But you're probably not. So you refactor it to a function to reduce code duplication. Good, but now you need to sort different types, and with different comparison logic - so you add a function pointer for a comparison function. In other words, you get the stock qsort:

      void qsort(void* array, size_t elements_count, size_t element_size, int (*comparer)(const void*, const void*));

      And at that point you're already slower than C++'s std::sort, because:

      1) qsort takes a function pointer and do indirect calls through that, while std::sort will take a function object and inline all calls (in theory a C compiler can inline calls via function pointer as well, but I've yet to see one that does that).

      2) The qsort comparer argument always takes its arguments by reference, even when it's some type that's more efficiently passed by value and in a register (e.g. int). std::sort function object doesn't have this limitation - it can take arguments either by value or by reference.

      The real problem here is the lack of genericity. If you hand-code the sort for every specific case (type + comparison function), you'll be better off in C, but then you'll get tons of duplicate code, which is bad for maintainability. And C doesn't offer any decent ways for compile-time code generification (only macros, but they are so limited and generally meh), so most people just use the more-generic-but-slower solution and don't bother. And - end up slower than C++.

      It should also be noted that the above C vs C++ comparison isn't limited to C++. For example, a direct std::sort analog can be written in C#, fully generic, and all arguments will apply to it as well (JIT will inline the comparer call, and so on).

    15. Re:He's also right by Anonymous Coward · · Score: 0

      Well, I once heard of a Java Program that was faster than a C program that implemented the same functionality. But, that was a special case... The C program didn't have access to kernel-level threads, but the Java program effectively did. So, the C program had additional overhead with threading. But, that's more of an issue of what libraries and whatnot each program had to talk to the OS than qualities of that particular programming language.

    16. Re:He's also right by synthespian · · Score: 1

      What's the use of "very fast code" if it's full of security holes and periodically infested with bugs?

      Such is the case with C/C++. I think the Linux kernel, the joke called the Microsoft product line, and the exception that is OpenBSD C hacking illustrate my point.

      Fact is, C sucks for most things. Too bad we don't have very good free Ada or Eiffel compilers (the ones dual-licensed with GPL have had zero impact - because of the GPL, I think).

      --
      Main difference between the BSD license and the GPL license: one is from California and the other is from Massachusetts
    17. Re:He's also right by countach · · Score: 1

      There are some things in Lisp that CPUs can do efficiently, that C can't guarantee to do efficiently. For example, tail recursion without growing the stack. You might say then that Lisp is "more like how the processor works". You might be surprised how close to C output a good Lisp compiler might get.

      And there are plenty of things in C that have a lot of stuff going on under the bonnet too. malloc() for example can be quite a complex and inefficient call, that has to do a lot of housekeeping to find a block of the right size and stop fragmentation.

    18. Re:He's also right by Anonymous Coward · · Score: 0

      Forget LISP/Haskell/Python--just use Java now if you want C-level of performance in a more conventional language.

    19. Re:He's also right by Anonymous Coward · · Score: 0

      I don't know what language you use, but I use java, and I think that your comments are spot on as far as the JVM is concerned.

      Garbage collection is now so good that heap memory allocation intensive programs will likely run slightly faster--in addition to vastly safer--in java than C.

    20. Re:He's also right by kiatoa · · Score: 1

      Garbage collection is now so good that heap memory allocation intensive programs will likely run slightly faster--in addition to vastly safer--in java than C.

      I sure wish my day to day experiences with java based software supported your statement.

      --
      90% of the wealth is in 2% of the pockets. Bummer to be in the majority.
    21. Re:He's also right by arth1 · · Score: 1

      Reason being is that C is the closest high level language to how a processor actually operates.

      Not really. But it translates relatively well into assembly, and if you know the platform you're compiling for, you can even write your C to produce especially efficient assembly code. Knowing how a processor handles a pointer and a pointer to a pointer, or how many registers can be passed in function calls without having to store them on the stack can give you an edge.

      Forth is a language that is even more tied to how processors work; like the CPU, you queue up one operation at a time, with a minimum of arguments and conditional jumps with fall-through. However, what it gains on the swing, it loses on the roundabout with excessive stack usage. (In its purest form, it even depends on executing from the stack.)

      Then you have the high level languages that compile to pseudo-code, which is run in a simplified interpreter at near-ML speeds. UCSD-pascal with p-code was probably the best known example until Java came. It can be argued that p-code and java bytecode is closer to how a processor really operates. But few would ever write programs directly in p-code or bytecode, so they don't really count.

    22. Re:He's also right by fnc · · Score: 2, Interesting

      For what I known the fastest high level language is Fortran. Besides being the first language high level language and obviously have lots of work of compiler optimization done, it has a very restrictive type system that does not have pointers (or have them in a very restrictive way), so the compiler can do optimizations in arrays that would be unsafe in a language like C.

    23. Re:He's also right by graphicsguy · · Score: 1

      These days we are also starting to think how we can utilize vector processors, which to gamers are quite familiar as their video cards. Everyone has one, either they know it or not, nowadays they install a 500 mFlops graphics card in PCs in use by hotel receptionists.

      Think about what languages these GPUs are programmed in (CUDA, Cg, GLSL, etc.), and what language do these languages in turn try to mimic? Oh yeah, C. :-P

    24. Re:He's also right by amn108 · · Score: 1

      Well, I did not ever say that garbage collection rivals the speed of C-compiled programs. What I said was that it made sense lately to a lot of VM-engineers to allocate variables of all kinds on the stack anyway, so the difference is not there anymore. Heap allocation will always be slower, and I responded to the guy because he appeared to be saying that never, no matter what, shall "high-level" languages rival C in speed. Which I think is an inaccurate statement :-)

    25. Re:He's also right by amn108 · · Score: 2, Insightful

      Oh, it is NOT because they TRY to mimic C, I assure you.

      C is closest to the metal, after assembly language. General purpose computing on proprietary vector processors is something new. Naturally, just as with earliest computers, people are careful and the first compiler to pop up is the very straight-forward C-like, which is a natural first (and simplest) choice. C was designed to be close to metal, but this also made for a very simple compilers. C is very efficient in that sense - for RASP (Random Access Stored Program) Von Neumann architectures, which 99% of todays computers are - it is a real good compromise for a language that is quite readable and yet does not require state of art compiler to translate REALLY efficiently for the machine to understand. So, I think, they did not mimic C to run shaders for its beauty and programming potential, it is just that C is the next step of programming these shaders above bare assembly.

      Just as with all software however, in my opinion, C becomes more difficult to maintain for very large programs, because the programmer tends to loose oversight of the problem among all those close-to-metal C primitives and/or misses on optimization, assuming stuff without profiling or inevitably negating optimization for one platform while trying to adapt for the other with his cross-platform C.

      Anyways I may be wrong here, but from my experience I start to lean heavily towards starting to trust automated translators (compilers) more than I trust MYSELF when optimizing C code, and I know a lot about optimizing C code. Of course we are very far off from having compilers produce the kind of inverse square root functions John Carmack has written, but then again, an inverse square root function is a mathematical function, not something a compiler needs to write itself.

    26. Re:He's also right by ultranova · · Score: 1

      So, the upshot of this is that C is very close to the bare metal of how the system works. Thus if you are good with it, you can produce extremely efficient code. The higher level stuff may be nice, but it all slows things down. When you have a managed language that takes care of all the nasty stuff for you, well it is spending CPU cycles doing that. Now the tradeoff is quite often worth it, since CPUs have loads of power and maintainability of code is important, but don't trick yourself in to thinking it is more efficient.

      However, all of that is only true if you're smarter than the compiler. If your compiler is a human-level or better AI, then it doesn't matter what language you write in, because it can simply treat the high-level language as a "design document" and do all the same clever low-level optimization you could; if it's smarter than you, it then it'll do even better. That's why high-level languages today are much closer to C than they once were, and C itself closer to assmebly than it was. The speed of all languages are converging.

      In the far future, I see computers becoming intelligent agents with strong AI, who aren't programmed in the commonly understood way, but rather are given (possibly very generic) tasks and create subroutines - which are incrementally improved through experience - to perform them. Ever-higher level programming languages are steps in that direction, pushing more and more details to the computer itself.

      Strong AI will emerge from a programming language which is high enough level to be indistinguishable to giving instructions to a human.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    27. Re:He's also right by SL+Baur · · Score: 1

      You can find Lisp dialects that efficiently use native machine types and have little runtime cost due to having weak type systems (just like C) where casting is easy and the responsibility for crazy results lives with the programmer and the limited ability of the compiler to check some static cases.

      Sigh. That's just plain ignorant. The checking has to be done somewhere, else you have a Microsoft Windows that's open to all kinds of holes. The compiler (with strong, static typing) can do it faster than the programmer no matter what architecture is running the code.

      You can either build that typing into the language itself or hand code it. It's a lot more efficient to build it into the language. That way experts get to decide the actual code. I can and have written hand optimized assembly language. I have not written assembly language for every underlying architecture that my code has run on. A higher level language than C can optimize the concept.

    28. Re:He's also right by haapi · · Score: 1

      "Reason being is that C is the closest high level language to how a processor actually operates."

      Absolutely true. For a PDP-11.

      --
      Well, apparently, you only have to fool the majority of people for a little while.
    29. Re:He's also right by podperson · · Score: 1

      If you have equal skill in optimization, but not necessarily equal time to spend optimizing.

      Surely the effort required to optimize a program should factor in. Here, C may not fare so well.

    30. Re:He's also right by graphicsguy · · Score: 1

      Oh, it is NOT because they TRY to mimic C, I assure you.

      Are you aware that NVIDIA's Cg stands for "C for graphics"? Also, CUDA "uses a recursion-free, function-pointer-free subset of the C language, plus some simple extensions."

    31. Re:He's also right by amn108 · · Score: 1

      Umm yes, now how does it contradict anything I have said? I am not sure why you have asked me this. Perhaps just a question?

    32. Re:He's also right by aevans · · Score: 0

      C is so far from the processor, it's not funny any more. Not only do compilers have macros and optimizations that completely mutate the code, but CPUs have their own virtual stack (and cache) in between that shuffles things every which way but right. And in between, you have operating systems that abstract everything from memory management to scheduling. Long gone are the days when C got anywhere near the "bare metal".

  50. It must be attention whore day at Slashdot by Anonymous Coward · · Score: 0

    I will prove that anything written in a higher-level language will not be as fast as my implementation of it in C. I leave this challenge out to anyone to take. (*)

    How are you going to prove this dipshit? Do you have some induction step that can prove this? Or a formal proof to offer?

    Yes, if I give you Implementation X in LISP of some algorithm, I do believe that given unlimited time and resources you can probably rewrite it faster in C. But I think you're missing the point.

    And you don't know shit about the word proof which makes me doubt your other claims.

  51. Re:World's "Fastest" Small Web Server Released, Ba by Tablizer · · Score: 1

    If we are talking about pretend programming languages, Ada's [Lovelace] language still beats out this guy by over 100 years.

    But Ada's notation was not "high-level". Perhaps the statement should have been "second oldest surviving high-level language". There are also Grace Hopper's experimental languages in the mid 50's that led to COBOL. It may be argued that these be counted with COBOL since they heavily influenced it, although arguments could be made either way.

    Perhaps they should have said, "one of the earliest high-level languages", then it won't generate controversy, and we wouldn't be having this side-bars on slashdot. Naw, we like side-bar trivia contests, admit it.
       

  52. The algorithm he uses can be implemented in C... by master_p · · Score: 1

    ...so what we have here is a faster algorithm, not a faster programming language.

    LISP is better than C for other reasons, not speed...

    By the way, why some Slashdot pages are not rendered correctly by Firefox 3 on Windows XP (SP3)? I have to select the text with ctrl+A to see the header of each post.

  53. Mod parent up. Good comment. by Futurepower(R) · · Score: 2, Insightful

    "... C is the closest high level language to how a processor actually operates."

    C was meant to be equivalent to a high-level assembly language. Someone told me that he was worried about coding in assembly language for a particular part of a video driver, but he discovered that, in that case, his C compiler wrote perfect assembly language.

    1. Re:Mod parent up. Good comment. by Jurily · · Score: 2, Insightful

      C was meant to be equivalent to a high-level assembly language.

      No, it was a general-purpose high-level language. It's just that our definition of "high-level" has changed over the past 40 years. Now we have Python and Ruby.

    2. Re:Mod parent up. Good comment. by Anonymous Coward · · Score: 0

      C was meant to be equivalent to a high-level assembly language.

      No, it was a general-purpose high-level language. It's just that our definition of "high-level" has changed over the past 40 years.

      "C is a relatively 'low-level' language. This characterization is not pejorative; it simply means that C deals with the same sort of objects that most computers do, namely characters, numbers, and addresses. These may be combined and moved about with the arithmetic and logical operators implemented by real machines."

      That's from Kernighan and Ritchie - the horse's mouth. So it really doesn't matter if the definition of 'high-level' has changed; attempts to turn C into a high-level language have names like C++,C#, Java...

    3. Re:Mod parent up. Good comment. by Anonymous Coward · · Score: 0

      > C was meant to be equivalent to a high-level assembly language.

      This is simply not true. The computer scientists who made this 'observation' had their tongues planted firmly in their cheeks.

      Assembly is untyped, unstructured, and verbose. It does not handle mathematical expressions. Anyone who thinks C is anything like assembly has not done any programming in assembly!

  54. "I want to believe in Lisp Performance" by Anonymous Coward · · Score: 0
  55. That's a myth. by Estanislao+Mart�nez · · Score: 4, Interesting

    Reason being is that C is the closest high level language to how a processor actually operates.

    Once you get things like branch prediction, speculative execution and pipelining into the picture, no, C isn't really any closer to how the processors operate. Making efficient use of a modern CPU involves detail at a much, much lower level than C exposes.

    The performance killer for high-level languages isn't really the abstraction away from the machine instruction set; it's garbage collection. And even then, it's mostly because GC tends not to play well with memory caches and virtual memory; a simple stop-and-copy garbage collector is actually algorithmically more efficient than malloc/free, but absolutely atrocious with caches and VM.

    1. Re:That's a myth. by TeknoHog · · Score: 4, Insightful

      Once you get things like branch prediction, speculative execution and pipelining into the picture, no, C isn't really any closer to how the processors operate. Making efficient use of a modern CPU involves detail at a much, much lower level than C exposes.

      The problem at that level is that you'll be seriously bound to a specific architecture. Even C, which is often called a portable assembler, is designed after a certain kind of assembler.

      The somewhat surprising result is that you can also improve performance (compared to plain C) with a higher level language. You need a higher-level perspective to tackle things like vector/parallel processing efficiently.

      --
      Escher was the first MC and Giger invented the HR department.
    2. Re:That's a myth. by hawk · · Score: 4, Insightful

      It's about using the right tool for the job.

      Some years, I do heavy computational programming. No so much number crunching, as bashing them into submission.

      I can do this *much* faster in a modern Fortran (90 or later) than in C. Not because C can't do the same things, and not because an optimized C can't get to the same results.

      The difference is that I can sit down and simply enter near algorithms of matrix math into Fortran, and the optimizer will go to town and give me near perfect code, which will be faster than what I would get with C (which would also take significantly longer to code). A skilled C coder could do a better job, and ultimately get roughly the same performance as I got from Fortran.

      This isn't because "Fortran is better than C," but because Fortran is designed and optimized by people who do this kind of stuff *to* do this kind of stuff. It can make very strong assumptions that C can't (and much of the hand-optimizing of C is essentially replicating these assumptions).

      OTHO, writing a modern operating system in Fortran *could* be done, but it would be painful, would take far longer to code, and would probably have atrocious performance.

      note: I believe that Pr1mos was largely written in FORTRAN IV.

      hawk

    3. Re:That's a myth. by Anonymous Coward · · Score: 0

      The problem at that level is that you'll be seriously bound to a specific architecture. Even C, which is often called a portable assembler, is designed after a certain kind of assembler.

      That's an interesting point. I'll bet Lisp runs at least as fast as anything else on a Lisp machine.

    4. Re:That's a myth. by cabazorro · · Score: 1

      You nailed it. Among other things, of course, it is how the memory gets managed by you and the libraries, in whatever language you choose, a determining factor in efficiency. Some languages lean toward managing the memory for you while other languages leave that to your own device. It would be naive and stupid to state that my program is efficient because was written in c..right? But I have read dissertations here and many places on how, given the right conditions, Java may very efficient managing memory not wasting cpu cycles(by efficient mean thrifty with resources) which is a stretch (don't go there). Indeed, the idea that just because something is coded in C, it is going to be faster than it's counterpart in a different language, well that is a myth.

      --
      - these are not the droids you are looking for -
    5. Re:That's a myth. by Zoxed · · Score: 2, Interesting

      > The difference is that I can sit down and simply enter near algorithms of matrix math into Fortran, and the optimizer will go to town and give me near perfect code,

      Ahhh: a breath of fresh air. As a programmer this is to me exactly how it should work. Not my language is better than your language but the programmer can get on with describing the solution, and leave the compiler to do the boring work !!

    6. Re:That's a myth. by TeknoHog · · Score: 1

      I agree completely. In fact my experiences also come from Fortran.

      I have a particular issue with these auto-vectorizing compilers developed in recent years. The idea is to parallelize a sequential C-style loop, which IMHO is completely backwards.

      In such a case, the programmer usually knows which processes are independent, but the sequential language forces them to write them as a loop. Then the compiler does a lot of guesswork to reconstruct this parallel idea. A higher level language would have solved this much more elegantly, since the parallel construct could be there all the time.

      --
      Escher was the first MC and Giger invented the HR department.
    7. Re:That's a myth. by TeknoHog · · Score: 1

      > The difference is that I can sit down and simply enter near algorithms of matrix math into Fortran, and the optimizer will go to town and give me near perfect code,

      Ahhh: a breath of fresh air. As a programmer this is to me exactly how it should work. Not my language is better than your language but the programmer can get on with describing the solution, and leave the compiler to do the boring work !!

      Seconded. This is why I like Fortran and Python, I'm interested in solving a higher-level problem, not learning the details of an architecture. Of course, these languages are not suitable for operating system kernels, but how many of us write them anyway, as opposed to userspace applications?

      --
      Escher was the first MC and Giger invented the HR department.
  56. Turing-Completeness has nothing to do with it by warrax_666 · · Score: 1

    Turing-Completeness only says something about what you can compute, not how efficiently you can compute it.

    --
    HAND.
  57. You insensitive clod... by TERdON · · Score: 1

    I'm working on embedded systems. Real men don't program desktop computers! :-P

    Small embedded systems are often sans FPU. Fixed point arithmetic is orders of magnitude faster on such a platform (I'm not sure what the numbers on desktop processors are but I wouldn't be surprised if it's slightly beneficial even there).

    --
    I have a really elegant proof for Fermat's last theorem. If this sig was only a bit longer...
    1. Re:You insensitive clod... by RegularFry · · Score: 1

      There's also the issue that it takes a Real Man to know how much there is to know about floats, rather than assume it'll all work out in the end.

      --
      Reality is the ultimate Rorschach.
    2. Re:You insensitive clod... by TERdON · · Score: 1
      --
      I have a really elegant proof for Fermat's last theorem. If this sig was only a bit longer...
  58. Young programmers should consider Common Lisp by LSU_ADT_Geek · · Score: 1

    As modern programming languages (Python, Ruby, and Scala) are implementing Common Lisp features (closures, variable capturing) and the online availability of Practical Common Lisp, it seems now is a good time for younger people to learn CL. The icing on the cake here is that there are alternatives for Vim users to develop Lisp without using SLIME.

  59. Re:And what makes you think that LISP is interpret by klapaucjusz · · Score: 1

    I really don't know much about LISP, but I'm having a hard time understanding why "performing a pass over each function" rules out being a "pure interpreter." Maybe we just have different definitions of what that means. Could you please clarify?

    Sure. A pure interpreter is an implementation that executes the code as it parses it, or at least as it walks the parse tree. An intepreter with a pre-pass is one that first walks the code, does some transformations or caches some data, and only then executes the code.

    Suppose you're implementing a BASIC interpreter. A pure interpreter would walk your BASIC program, and execute statements as it parses them. However, it will surely be more efficient to perform a pre-pass and remember the addresses of every line number, so that every GOTO doesn't need to scan the whole program to find its target.

  60. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 0

    Hi, i'm from Soviet Union. And i'd appreciate if both of you americans reflect on the great sacrifices that our troops have made so that you both can now grill your steaks today in this nice sunny weather.

  61. Re:And what makes you think that LISP is interpret by klapaucjusz · · Score: 1

    What would be an example?

    There are some restrictions on when macro expanders are allowed to be run which cannot be satisfied without performing a pre-pass. Sorry, I don't recall the details.

    I thought that some other Free CL implementations are interpreters, but I might be confused, CLISP does compile to bytecodes, and GCL uses gcc...

    CMUCL, CCL (formerly MCL), SBCL, Lispworks and ACL are native compilers. KCL, AKCL and GCL compile to C. CLISP compiles to bytecode. Heck, even Emacs Lisp is compiled (bytecode).

    (By the way, have you tried CCL yet? It's a very nice implementation, and since it's only been ported to Linux recently, a lot of people are not aware that it exists.)

  62. REPOST - with correction by ratboy666 · · Score: 4, Interesting

    Repost - lt should be replaced by lessthan sign...

    Trolling sure sounds easy, but...

    Gambit-C Scheme vs. C

    I'll make it easy for you. It's the two minute litmus test. Even easier -- I'll give you the pseudo-C code:
    Task: compute n! for n >= 1000.

    In Scheme (Gambit 4.2.8, using infix):

    int factorial(int n) {
    if (n lt= 0) {
    1;
    } else {
    n * factorial(n - 1);
    }
    }

    compile with: gsc f.six
    and run it:

    gsi
    Gambit v4.2.8

    > (load "f")
    "/home/user/f.o1"
    >(factorial 1000)
    4023...0000

    Your challenge? Write a C version in two minutes, tested and compiled. Now, as the final icing, run the C version on smaller numbers, and compare the performance -- did you forget to compile in small integer versions? (try factorial(12) a million times).

    I'll wait (another two minutes). Compare the performance against the LISP version. Did you have to write two versions -- one for big integers and one for small integers? That is pretty well the only way to keep a speed advantage... I hope you wrote it that way. Did you remember to put in 32/64 bit conditionals to retain your advantage on a 64 bit platform?

    I think your C code now looks like this (it should):

    #define FACT_LIMIT 12 -- for 32 bit int type, I don't know what the cutoff is for 64 bit.
    #include bignum.h -- I don't want to bother with quoting assume angle brackets /* This only gets executed a maximum of FACT_LIMIT times; leave it recursive */
    int fact_integer(int n) {
    if (n lt= 0) {
    return 1;
    } else {
    return n * factorial(n - 1);
    }
    } /* May wish to rewrite to an iterative form */
    bignum factorial(bignum n) {
    if (compare_lt(n, FACT_LIMIT)) {
    return int_to_bignum(fact_integer(bignum_to_int(n)));
    }
    return bignum_mult(n, bignum_dec(n));
    }

    You choose the bignum package to use. Or, for more fun, write it yourself. If you wrote it yourself, you remembered to switch to FFT style multiplication at bigger sizes? Or Karatsuba?

    Now, we have only coded to a recursive form, but, since bigints are not first-class in C, we don't know about memory reclamation (leakage). I hope you know the gmp library, or can roll up a gee-whiz allocator on your own. The gmp library would be cheating, by the way -- YOU DID CLAIM YOUR IMPLEMENTATION IN C.

    If recursion is viewed as a problem, the Gambit-C version can be recoded as:

    int factorial(int n) {
    int i;
    int a;
    if (n lt= 0) {
    1;
    } else {
    a = 1;
    for (i = 1; i lt= n; ++i) {
    a *= i;
    }
    a;
    }
    }

    I am sure that something equivalent can be done in the C version. But the normal flow of control stuff doesn't know about bignums. We COULD make the incoming parameter an int, I guess... which works for factorial() but may not be as workable for other functions.

    Answers:
    - gmp does better than Gambit-C on bigint multiply, using FFTs.
    - breaking the result into two separate functions is needed for C to come ahead.
    - yes, C is faster, at the expense of a lot more programming.
    - if I want to, I can simply drop C code into my Gambit-C program on an as-needed basis. The Gambit-C code still looks a
    whole lot cleaner than the C version, and ties it for small integer performance. The bigint performance is still a "win" for
    gmp, but I can use THAT package directly as well in Gambit-C.

    Win:
    - Gambit-C. The prototype was finished to spec in two minutes. Optim

    --
    Just another "Cubible(sic) Joe" 2 17 3061
    1. Re:REPOST - with correction by metamatic · · Score: 1

      Now that's what I call pwnage.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    2. Re:REPOST - with correction by Anonymous Coward · · Score: 0

      Answers:[...]
      - yes, C is faster[...]

      Win:
      - Gambit-C[...]

      Huh???

    3. Re:REPOST - with correction by ratboy666 · · Score: 2, Insightful

      Aw shucks, you caught me out! You AC guys...

      Sure, since Gambit-C uses C as its "assembler" level, it is possible to micro-optimize. In Post #2, I illustrate how to deal with that. In Post #3 you see how I deal with the "low-level advantage" issue.

      And, in response to you: I challenge that YOU cannot beat Gambit-C, even given six months implementing this stupid little useless program. Without resorting to pre-written code, that is, in which case *I* get to use the same libraries.

      To WIN, you have to show a 5% advantage in run-time. Otherwise, Scheme takes it. Simply because it IS a true HLL, and can represent stuff at a reasonable level, and is completely "safe".

      Go for it.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
  63. Mod Parent Down by toby · · Score: 1

    -5 Ignorant
    -5 Wrong

    --
    you had me at #!
  64. Is C really easier to write than Lisp? by Requiem18th · · Score: 1

    As a Python, Javascript and PHP programmer, you would think I lean to the Algol style of programming yet I find C brittleness unbearable.

    I don't know any Lisp but I was tough C at college and Lisp still looks more readable than C and it's micromanaging tendencies.

    I'm pretty sure a Lisp 101 would teach me to write Lisp as good as C in less than a semester.

    In short, I don't think the availability of C programmers and scarcity of Lisp programmers is due to Lisp being harder than C is it?

    And if it is, how is it? What's so easy about C? What so hard about Lisp?

    --
    But... the future refused to change.
  65. IGNORE ABOVE POST -- INCORRECT, LOOK FOR REPOST by ratboy666 · · Score: 1

    Subject says it all. I goofed, and used a less-than sign in the code sample.

    --
    Just another "Cubible(sic) Joe" 2 17 3061
  66. Paul Graham @ Yahoo! by shis-ka-bob · · Score: 1
    Paul Graham has been developing and advocating web servers in Lisp since at least 1995 . See http://lib.store.yahoo.net/lib/paulgraham/bbnexcerpts.txt

    From Wikipedia: In 1995, Graham and Robert Morris founded Viaweb, the first application service provider (ASP). Viaweb's software, originally written mostly in Common Lisp, allowed users to make their own Internet stores. In the summer of 1998 Viaweb was sold to Yahoo! for 455,000 shares of Yahoo! stock, valued at $49.6 million.[2] At Yahoo! the product became Yahoo! Store.

    --
    Think global, act loco
  67. Comparing what cannot be compared by loufoque · · Score: 1

    They're comparing an integrated webserver / web application with a general webserver connected to an independent application through unix sockets.

    Of course the first one is much faster, but it's not the same thing at all...

  68. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 0

    Might one point out that you didn't exactly rush to save anyone in either conflict: both had been going on for years before you decided to join in.

    But now, obviously, you're big enough to start your own, pointless, stupid wars.

    Please, give it a rest. The USA no more joined in either war to save anyone than the original combatants did.

  69. A Faster LISP version by ratboy666 · · Score: 2, Insightful

    And now for the grand unveil - the SCHEME (LISP) version, with integrated C code for the "super-speedy" inner loop. Just to illustrate that the SAME optimizations are available for the LISP programmer. This can be further micro-optimized.

    Note that it isn't much different from a "C" implementation that has the same optimization. Note the ease of moving between data types (we only worry about in a very cursory way). I am waiting for your pure C implementation.

    # In "normal" scheme syntax. Note escape to six syntax (for the C
    # developer. Replace [lt] with less-than before compiling

    # Define in-line C function for fast factorial within 32 bit constraint
    (c-declare #[lt][lt]c-end

    int fast_factorial(int n) {
        if (n [lt]= 0)
            return 1;
        return n * fast_factorial(n - 1);
    }

    c-end
    )

    (define fast-factorial
        (c-lambda (int) int "fast_factorial"))

    # The constant 12 is the largest factorial that can be computed in a 32 bit int.
    # Notice the function fast-factorial is also escaped: fast-factorial is actually a C expression.
    \int factorial(int n) {
        if (n [lt]= 12) {
            \fast-factorial(n);
        } else {
            n * factorial(n - 1);
        }
    }

    --
    Just another "Cubible(sic) Joe" 2 17 3061
  70. Re:World's "Fastest" Small Web Server Released, Ba by El_Muerte_TDS · · Score: 1

    But Konrad Zuse doesn't have a beard, so Plankalkül doesn't count.

  71. Re:And what makes you think that LISP is interpret by PaulBu · · Score: 1

    Hmm, CCL looks nice, thanks for the info!

    Will check it out -- but is is SBCL over here, and, after dealing with some quirks, it is actually pretty robust and fast.

    Paul B.

  72. LISP by edivad · · Score: 0

    LISP is a language that offload the parsing burden onto the reader. Sure is hell easier to write a LISP parser, but humans are taught since first grade to the "OPERAND1 OPERATOR OPERAND2" syntax, and LISP fscks that up. With so many languages available today, LISP is most definitely the wrong answer.

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

      The price of built-in syntax and operators is that it's much harder to create your own domain specific language. Hell, Lisp is so powerful that many noobs create an infix notation just like you're describing (in most languages this isn't even possible!) but then stop using it as they get better and decide they don't need training wheels anymore.

    2. Re:LISP by Anonymous Coward · · Score: 0

      Only if you don't do syntax and operators properly. For an example of how to do it right, see Haskell.

    3. Re:LISP by Anonymous Coward · · Score: 0

      As best I can tell, Template Haskell is still in the experimental stage, and the input must fit in a valid parse tree. If Haskell didn't already have, e.g., "let decls in e", and you wanted to add it, how could you possibly define "let" and "in" and get the parse you wanted? In Lisp you can create "let" from scratch in maybe a dozen lines and have it behave exactly as if the language designers had put it there from day one.

  73. Re:World's "Fastest" Small Web Server Released, Ba by Anonymous Coward · · Score: 0

    Zuse's computer was not Turing-complete.

  74. Re:Attention Pooftahs and Frenchies by shutdown+-p+now · · Score: 3, Informative

    Today is Memorial Day in the United States of America. We would appreciate you folks taking some time to reflect on our servicemen who gave their lives saving your asses in WW I and II.

    Hi, I'm from the country formerly called the Soviet Union. We would appreciate you folks learning your history, so that you'd know that USA wasn't "the country that won WW2". You might, for example, want to remember that over 3/4 of all German losses in manpower were on the Eastern front (5.5 million KIA total, 4.3 out of which are on Eastern front), and that over 10 million Soviet soldiers, and twice as many civilians, payed with their lives for that achievement.

  75. Re:The algorithm he uses can be implemented in C.. by colinrichardday · · Score: 1

    It does the same thing in Konqueror 3.5

  76. Disappointed by zakeria · · Score: 1

    I'm really annoyed at some of the comments I'm reading here regarding C compared to high level languages such as LISP. Many of the people on here call themselves nerds yet they seem to have no idea how basic functionality of a CPU works!!! I can't even be assed with this post ...

  77. Pointers aren't really confusing by BenoitRen · · Score: 1

    I don't really agree about pointers being confusing. Well, at first, sure, but once you 'get' them, like I did, it's pretty nice to work with them. I actually find the abstraction of pointers to references in languages like JavaScript, Java and .NET annoying because I never know what I'm actually passing along in arguments. That is, if it's the reference or the entire object. Those concepts have bled together in those languages.

    1. Re:Pointers aren't really confusing by poopdeville · · Score: 1

      Those concepts have bled together in those languages.

      Yeah... because it's an artificial distinction related to the misuse of "variables" in procedural languages like C.

      --
      After all, I am strangely colored.
  78. Horse to water... by ratboy666 · · Score: 2, Insightful

    We now come to the final post in this series.

    The speed in C comes from the direct hardware "low-level" thing. In the domain of "int" types on a 32 bit machine, I would say that the most efficient (well, one of the most efficient) implementations of factorial() would be:

    #define factorial(n) ((n) 0 ? 1 : fact_table[n])
    int fact_table[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 39916800, 479001600 };

    Can you hear the l33t-speak? I codez the C r3al g00d! My factorial function only takes a nanosecond or so! And, it ONLY takes two instructions! No, let's do better. We can DOUBLE the speed of this puppy. Just assume that negative numbers will never be passed in.

    #define factorial(n) fact_table[n]

    That's one fast function now!

    This is 32 bit int type only. Not a very interesting or useful case. 64 bits? Brings us to 20! or so. It is certainly a major benefit to Scheme to have the bignum built-in. Have you finished the C version without gmp yet?
     

    --
    Just another "Cubible(sic) Joe" 2 17 3061
    1. Re:Horse to water... by Anonymous Coward · · Score: 0

      May I suggest an English wording of a challenge related to yours that will drive the point home?

      "Write a program that takes three integers in the range of 1-6 as arguments, call them a0, a1, a2. Write to a file or standard output the result of the unit and tenths decimal digits of the square rots of each of the first 10*((a0*5^2)+(a1*5^1)+(a2*5^0)) factorials 1000000*((a2*5^2)+(a1*5^1)+(a0*5^0)) times. The arguments a0, a1, a2 should be generated by three rolls of a fair six-sided die."

      Make a list of 60 fair 6-sided die rolls, use sets of three of these numbers as arguments for each run.

      Fastest time to correct completion across 20 invocations using an identical list of die rolls on any given test system wins. Concurrency, parallelism, pipelining, memoization and other techniques are acceptable.

  79. Wrong Title... by Anonymous Coward · · Score: 0

    Worldth "Fathtetht" Thmall Web Therver Releathed, Bathed On LITHP

  80. Isn't this implementation? by tjstork · · Score: 1

    Aren't we comparing an implementation of Ruby to an implementation of Lisp? Excuse me, but I think that saying one programming language is faster than another is like saying English is faster than French. A language is just a set of formalisms for communicating. I'd be more than willing to bet that one could have an implementation of Ruby that could smoke Lisp or and be on par with the likes of C# or .NET. I mean, what if one wrote a Ruby with its guts in straight assembly....

    --
    This is my sig.
  81. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 0

    Hello from an American. I would like to say that there are those down here that do appreciate and value our Northern neighbor! It is easy to forget and mythologize (?) your own history. I know that my relatives who fought in those wars were more than happy to have the assistance of anyone willing.

    My grandfather (Pacific theater) and great uncle (Europe) both fought in WWII, but did not talk much about anything except great generalities. I do remember my uncle talking about ow happy they were to hear the bagpipes of a Scottish unit coming to help them. Remembering that others shared in the fight, the loss and glory does not diminish ones self.

  82. Re:Attention Pooftahs and Frenchies by nothing2seehere · · Score: 1

    Hi, I'm from a country currently called the United States of America, and I'd like to remind yet another citizen of the former Soviet Union that WWII wasn't fought only in Europe.

  83. Re:World's "Fastest" Small Web Server Released, Ba by Arker · · Score: 1

    LISP, the world's second oldest high-level programming language.

    That threw me right off, plankalkül is a rather obscure claimant, but assembly is the oldest surviving-and-useful high-level language. Now there are third-generation super-high level languages so perhaps it makes sense to call assembly "mid-level" but it sure as heck isnt low level. Low level programming means direct machine code.

    --
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Friends don't let friends enable ecmascript.
  84. My Java-based server results by danielcota · · Score: 1

    I have a web server which I built from scratch in Java (even built my own Stream buffers). The web server is currently being used to serve http://art.othernet.com/ in addition to some other websites. Benchmarking my server using the same schedtool/ab parameters, spits out 5896 requests/second. This is including dynamic html generation.

  85. Re:World's "Fastest" Small Web Server Released, Ba by Anonymous Coward · · Score: 0

    C abstracts away details of the machine, which is why it is (barely) a high level language and assembly is not. And Lisp is far older than the only surviving assembly languages I know of: x86 (1978), ARM (1983), and x64 (2003).

  86. Updated with instructions for running it by Anonymous Coward · · Score: 0

    Thanks for all the attention guys. I will try comparisons with a couple of servers.

    The immediately appearing comments were borked, I've fixed them now. Please give it a shot!

    http://john.freml.in/teepeedee2-using

  87. uninteresting by speedtux · · Score: 1

    It's uninteresting whether you can, in principle, write something that is as fast or faster.

    The interesting metric in many situations is whether, given the same amount of development time, you can produce something that is faster while being as reliable and functional.

  88. C only fast for small, simple problems by tartley · · Score: 1

    > It must be a small challenge involving a relatively simple task.

    I think an interesting point is that, for problems larger than small, well-defined tasks (ie. any real world project), then the speed advantages or disadvantages of the language start to get swamped by the choice of algorithms.

    I spent some time working through the small programming challenges at projecteuler.net. It is worth noting that the submitted solutions by users, in many languages, vary in execution time over many orders of magnitude, and my casual inspection seemed to show that the thing that correlated with fastest execution speed was not choice of language, but choice of algorithm.

    The programmers submitting solutions are amongst the set who are voluntarily spending their own time to do this - hence while they aren't the best programmers out there, they also probably aren't the worst.

    My conclusion is that if you can afford to get a good programmer to spend all day optimising a small bit of code, then yes C is going to be fastest. But as soon as the problem gets larger, or as development time is reduced to more normal proportions, then most half-decent programmers choice of non-obviously sub-optimal algorithms is going to swamp that. A high level language that supports discovery and implementation of the right algorithm, by giving the programmer less low-level detail and fewer lines of code to worry about, is going to claw back some ground.

    This matches with my own experience of Python. People expect that performance will be terrible, and when we measure it in benchmarks, it is terrible. But in real-world projects, it is great. So what's going on?

  89. Re:Attention Pooftahs and Frenchies by shutdown+-p+now · · Score: 1

    Hi, I'm from a country currently called the United States of America, and I'd like to remind yet another citizen of the former Soviet Union that WWII wasn't fought only in Europe.

    We know it well enough, since USSR participated in the Pacific Theatre, albeit in a relatively minor way (12,000 KIA - but proportionally it's larger losses than those of U.S. in Europe, for example).

    Even so, Pacific theatre was much smaller than European one. Again, if you look at military casualties - Japanese only account for 1/4 of all Axis losses.

  90. Re:Attention Pooftahs and Frenchies by dugeen · · Score: 1

    Yes, the gap between Memorial Day and November 11th symbolically represents the 2-year gap between the start of WW2 and the US entry into the war. You can keep WW1 by the way as, unlike WW2, it was fought between fascists rather than against them. Now, getting back to the subject of LISP, fast it may be, but if I wanted to write code that was hard to understand I'd use FORTH or a macro assembler, not some god awful mess of brackets that only John McCarthy understands.

  91. what is faster by Anonymous Coward · · Score: 0

    what about Assembly vs. C ?? or Assembly vs. LISP

  92. Here's the problem with Common LISP by Anonymous Coward · · Score: 0

    Common LISP source that runs on one interpreter isn't guaranteed to run on another interpreter.

    You can have one standard library function that returns the values of an ASCII character represented as a symbol... but those aren't defined in the standard. For example, you can have one interpreter's library have that standard function return #\NewLine while the same standard function returns #\Enter. that's just one tiny example but it bugs the shit out of me.

    That's why you see a lot of Common LISP libraries out there have clauses in their functions to run different code depending on which interpreter is running it. Very very annoying, and probably a maintenance hassle.

    Has any effort been attempt amongst the maintainers of all the different CLISP interpreters to try to enforce some consistency that was overlooked in the original ANSI standard?

  93. grow up by Anonymous Coward · · Score: 0

    You guys are reading far far too much into an excited guys remarks on his blog. He did achieve a lot by making a 'ancient' 'slow' programing do a task fast. Appreciate him for it.

  94. Re:Attention Pooftahs and Frenchies by DarkGreenNight · · Score: 1

    But... but... Nov. 11th is a horrible date for outdoor grilling! That would ruin the holiday entirely. I don't think you really grasp what Memorial Day is all about...

    Grilling? Veterans? Remind me not to come to any barbecue on this date.

  95. It is easy to make a C compiler. by Futurepower(R) · · Score: 1

    C was "general-purpose" only for operating system developers. It is easy to make a C compiler for a new processor. When C was invented, users were developing much more limited programs with very limited processors, and the limitations didn't matter as much.

  96. Re:Attention Pooftahs and Frenchies by nothing2seehere · · Score: 1

    We know it well enough, since USSR participated in the Pacific Theatre

    Declaring war on Japan in August 1945? The USSR "participated" by showing up for the yearbook photo. Typical Stalinist land grab. And quite frankly, it's hard to celebrate the Soviet contribution to the European front when Russia was originally so happy to indulge and assist Hitler. You let a wild dog off the chain, you deserve to get bitten.

  97. Re:Attention Pooftahs and Frenchies by Anonymous Coward · · Score: 0
    [

    You might, for example, want to remember that over 3/4 of all German losses in manpower were on the Eastern front (5.5 million KIA total, 4.3 out of which are on Eastern front), and that over 10 million Soviet soldiers, and twice as many civilians, payed with their lives for that achievement.

    So you suffered a two to one loss ratio and are still willing to brag about it? Interesting. I suggest a different strategy next time.

  98. Be careful what you ask for by alispguru · · Score: 1

    I can't see his implementation as I type, but since it's Lisp, it probably has these two features:

    * Compiled from (S-expression-based) markup to machine code
    * Can be modified without restarting web server

    The first would be really hard in C without a preprocessor. Your markup doesn't have to be S-expressions, but it should be some semi-readable DSL.

    The second is very hard in C, as it requires having the compiler around at runtime and dynamic redefinition of code.

    If you can do both of those in C, you're really good.

    --

    To a Lisp hacker, XML is S-expressions in drag.
    1. Re:Be careful what you ask for by Anonymous Coward · · Score: 0

      The S-expression parser is a pain to write in C, unless you use a BNF parser generator. But once the framework is in place, it is truly mechanical to write the state machine's transition table. (Indeed, my own challenge was to write a JSON parser, so I have thought about the issue. My Haskell implementation is about 200 lines)

      You don't need to have a dynamically changing runtime (or rather, it's pretty easy to write one). You just have to write and use a C-macro implementation of parametrized types, and a Hindley-Milner type checking system. Then you gain the algebraic power of static typing, and can "dynamically" do stuff by defining types.

      Yes, you have to be "really good", but it's not impossible, and there's plenty of practical knowledge out there, in academia land.

  99. Re:Attention Pooftahs and Frenchies by ultranova · · Score: 1

    * - it's worth noting (though I can't find the citation) that the method by which the cdns held kapyong against the 3-5:1 odds was by calling down artillery on their own position

    Don't you think that that's taking sporting spirit a bit too far ?-)

    --

    Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  100. Gary Larson Perspective by Mybrid · · Score: 1

    Lisp always reminds me of a Gary Larson cartoon. There is a six-year-old sitting in a classroom with one of Larson's typical frumpy teachers with big glasses at the blackboard. The caption reads, "Teacher, may I be excused? My brain is full."

    Having gone the Engineering route of getting my CS degree, I have to say that nothing quite fills the brain like Lisp. Not Quantam Mechanics, not Special Relativity, Not Word Problems, Not Linear Transformations, and Not Shakespeare.

    At Berkeley they use Lisp to weed out the less than committed, as the very first programming class a Freshman takes one takes is in Lisp. It was quite effective at getting Freshman to drop like flies.

    Lisp hurts the brain. There is something not quite right about thinking in lambda functions. Or at least normal in the typical notion. Far be it from me to promote being normal, I'm a big fat weirdo, but the Lisp crowd, it seems to me, is a religious cult and has always used the language as an Elitist barrier. A computer science definition of machismoism: you must claim Lisp is the end all, be all. Paul Graham certainly fits into that elitist crowd. If normal is meant to mean not wanting to aspire to be part of some elitist crowd simply because one's brain is perceived superior by some arbitrary standard, count me normal. Or count my brain as full.

    1. Re:Gary Larson Perspective by Anonymous Coward · · Score: 0

      Lisp is meant to let you create the language you need for a project, and in twenty years I've never seen a better way to do that. It does change the way you think about programming, which is why it's hard to learn. There are a few other language families like that: Forth, Prolog, Smalltalk, Haskell. Everything but those is easy to learn but a waste of time because it's not really any better than the ones you already know.

      And who's elitist? Everyone relying on Lisp would be much better off if more people used Lisp--better support, more opportunities, less reluctance from managers and business partners. The one thing they won't do is to make Lisp less powerful just to appeal to more people, because that would defeat the purpose even if everyone didn't know it wouldn't work.

  101. A small bit of dissent by marcus · · Score: 1

    While I agree with most of and the gist of your post, I must take exception to this:

    ...For example, in days past C was popular because CPU cycles were a lot more important than they are now, and memory sizes were a lot smaller than they are now...

    If you think that CPU cycles and memory sizes aren't so important these days, just ask M$ about Vista. If there is any one thing that has made Vista a bust, it is M$ thinking that execution speed and efficiency don't matter much anymore.

    --
    Good judgement comes from experience, and experience comes from bad judgement.
    - W. Wriston, former Citibank CEO
  102. Re:Attention Pooftahs and Frenchies by shutdown+-p+now · · Score: 1

    So you suffered a two to one loss ratio and are still willing to brag about it?

    Brag? No, I'm not willing to brag about so many deaths. I just wish to remind that, ultimately, they weren't pointless, and that largely with them the price of victory - for all Allies - was paid.

    Or are you willing to claim that superhuman American Rambos could achieve the same 10-to-1 kill ratio against Germans, especially early in the war, as they did against Japanese, if they only tried?

    It's also worth remembering that USSR - unlike US or UK - had to fight the Germans on its own land. And we didn't have France's option of surrendering, either, knowing full well what Nazi's plan for Eastern Slavic people was. Furthermore, Eastern Front was much less "civilized" than Western one - keep in mind than Nazis considered Russians untermenschen, and communists Jewish agents, so POWs were routinely massacred on the spot, and prisoner camps for Soviet prisoners were much more brutal than those for Western Allies, and the death rate was much higher.

    Germans lost over a million of their soldiers fighting for one city alone - Stalingrad. That's over 1/6 of their total losses in the war - and payed pretty much 1-for-1 with lives of Soviet troops. There was nothing even close to that kind of war grinder in Europe, much less the Pacific, so there's nothing you could possibly compare Soviet losses to, and say, "oh, this really could be done so much easier". Because no-one else was willing or able to actually do it.

    Interesting. I suggest a different strategy next time.

    In that case the winning move was to strike first. If the USSR did that back then, then, trust me, the Iron Curtain would be much farther to the West - if there would even be one at all. It's not something that you (or me, for that matter) should wish for.

  103. Is this news ???? by Anonymous Coward · · Score: 0

    Why is this news ? Seriously, CS teacher have been shouting for 51 years now that Lisp is faster than C (that's right, 14 years before C was invented), and that functional programming is faster than procedural programming. Is it because it's faster (faster it is, but significantly faster, it is not), or because it is in Lisp (nope: the second, or third, or whatever the nth such of it's kind), or because it's fast AND in Lisp ?
    Come on... do we really need this ? Is there something new here and in Lisp that's usefull to my profesional career, something classical like a shitty web 'enterprise' application ? I agree, maybe my career has taken a rather 'shitty' course, but is this article somewhat based on reality, or do we just have 'high expectations', that will remain unfullfilled in another 20 years (will web development still be around in 20 years ? I'm sure CS teachers will).
    I don't hate CS teachers, by the way.... but this guy:

    - wrote his own bechmark platform to test his app.
    - says 'automated gc is rubbish'
    - tells you to write your business monetary code using.... integers for the pennies calculation !
    - prefers command based compilation to inline compile !!

    When will we get over with the 70's ? Can we start to finally build something that is useful to someone ? Way yo go /., this really shows you're serious about article selection ! I just guess we'll just have to wait for the next "picobrowser in Scheme released, faster than Chrome but no HTML nor Javascript support, only works in Emacs platforms" super-mega-duper article.

  104. Re:World's "Fastest" Small Web Server Released, Ba by Arker · · Score: 1

    A revisionist definition.

    When I was learning CS Assembly was the definitional example of a high level language. Obviously Pascal/C/Lisp etc. are higher level, but all of them are easily distinguishable from true low-level code.

    --
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Friends don't let friends enable ecmascript.
  105. More than one way to quickly skin a cat by itsybitsy · · Score: 1

    Actually you're not quite right about C... it's not that efficient at all... most C instructions generate many actual machine instructions so C is quite removed from the bare hardware and how "the processor actually thinks" dude. Assembly language is much closer to the metal. Yes it's not a "high level language" but then neither is C, not really! C is a low level systems language.

    "Pointers" are not to be feared, mistakes with pointers are what is feared. Many higher level languages simply prevent those mistakes while providing all the usually necessary operational flexibility.

    For sure "message sending languages" such as Java and Smalltalk implement programming paradigms that the processor doesn't know about.

    Modern processors execute multiple instructions per cycle (instruction level parallelism). The game of speed is all about filling those instruction slots with useful productive instructions and not letting them go to waste unused. EVERY LANGUAGE that aims for any amount of speed must meet the challenge of filling those slots.

    C compilers are notorious for NOT filling these instruction slots for each cycle.

    Often it's not the compiler's fault since the code they are compiling is too sequential or branches too much to fill all the slots in a cycle. Also all the slots on the cpu are not created equal and may not even be the same across all versions of a manufacturers chip line.

    Assembly will almost always beat C even hands down since it's always possible to write better code than the compiler can. It's a matter of HUMAN TIME COST. Assembly usually takes longer to write than C just as C usually takes longer to write than code in higher level languages.

    So when you are interested in speed, is that speed of execution or speed of development where dollar and human time cost is paramount?

    There are efforts underway to make the compilers for languages like Smalltalk just as fast as C by the use of many techniques including the use of hidden inlining of code (this is effective in Smalltalk since the methods on classes tend to be very short at an average of under nine lines) and custom compilation of methods based on discovered object types. Essentially message sends are eliminated in many cases and types are discovered and specialized versions of the code is compiled for those types - either on the fly or at development time. In languages like Smalltalk all variable references are pointers references so pointers are not to be feared as the spycraft-fu mistakenly asserts. In fact a uniform use of pointers makes the language easier to understand while maintaining a one to one mapping of "object structure" to "how the machine thinks" - you could not have a closer mapping! The advanced work currently being done looks like it could bring Smalltalk compilers to produce code that is consistently at or above the speed of C compilers. Oops.

    Remember the game is filling the instruction slots in modern super scalar processors. (http://en.wikipedia.org/wiki/Superscalar).

    One of the hidden costs of C is the debugging time when things go wrong.

    Recently I undertook the task of updating an 15 year old program written mostly in C and C++ with a good bit of Assembly Language. I didn't have to change the assembly language one iota since it was "well thought out". As for the C and C++, both had many errors of the classic sort one finds with C based languages: buffer overflows left right and center - even where they were not expected! Funny enough one of the bigger non-buffer overflow bugs was found by tracing an unexpected buffer overflow as it did it's damage. It was also interesting that adding any code to "manage" buffer overflows would noticeably slow down (by 10% or more on inner loops) the program which was a heavy data cruncher. Once again the number of lines of code generated for each line of C was many, with numerous possible assembly optimizations still possible.

    Sure C might be faster but often that's because the C programmers took too many BIG risks with the

  106. Re:World's "Fastest" Small Web Server Released, Ba by Anonymous Coward · · Score: 0

    > A revisionist definition.
    > When I was learning CS Assembly was the definitional example of a high level language.

    Sez you. I'd like to know what school you went to, because assembly does not abstract details of the hardware AT ALL. It is a low-level language.

  107. Re:World's "Fastest" Small Web Server Released, Ba by Anonymous Coward · · Score: 0

    Labelling. A small thing, but they were one of the vast improvements of assembly over coding directly in binary. Of course you may not count not having to redetermine the memory location of pieces of code and data as code changed size as a hardware abstraction.