Live data from Hacker News

Make Lisp 15x faster than Python or 4x faster than Java

blog.postabon.com

11–20 of 100 posts

Re: Make Lisp 15x faster than Python or 4x faster than Java

#12
Thanks, that's interesting. My own main optimization problem is always reducing the memory usage of large in memory data sets. I found that languages like Java and Python, which don't support structured value types and use references/pointers everywhere, are basically unusable for my my purposes.

Now, I wonder whether I could use Lisp for what I do. One basic necessity would be to have a way to define a structure like this

  struct s {
    int32_t x;
    int32_t y;  
  };
and then create an array of that type as struct s a[size], which uses exactly size * sizeof(s) bytes in memory. A further requirement would be to have a library of data structures (balanced trees, lists, hash tables) that support storing such structs directly without using pointers everywhere.

Do you have any idea whether that could work with SBCL?

Re: Make Lisp 15x faster than Python or 4x faster than Java

#14
post #3
post #2

The most common way to compute your distance from a deal is to assume the earth is a perfect sphere I thought you would only really be finding deals at distances small enough to just assume the earth is flat. Or at least, aren't those the only ones people would actually be interested in? If it's beyond my physical reach, I don't care how far it is. I'll get it shipped. Or am I missing something?

You're absolutely right - in my experience the pythagorean theorem has less than ~50 meters difference from the Haversine formula for distances less than 20 miles or so. In the actual code I use a simple heuristic to decide when to use which calculation. Like I mentioned in the post, the distance function presented is a bit of a simplification I invented for pedagogical purposes (my goal was to examine languages, not…

The distance the swallow flies doesn't seem very interesting for many cases, where the terrain forces you to take a much longer route due to bridges, train track crossings, etc. Wouldn't you be better of using the Google maps API to return the length of an actual route to the target?

Re: Make Lisp 15x faster than Python or 4x faster than Java

#16

Thanks, that's interesting. My own main optimization problem is always reducing the memory usage of large in memory data sets. I found that languages like Java and Python, which don't support structured value types and use references/pointers everywhere, are basically unusable for my my purposes. Now, I wonder whether I could use Lisp for what I do. One basic necessity would be to have a way to define a structure lik…

I think you can do that - although I'm not entirely certain how much overhead a struct (defstruct) has. Array allocation has no overhead, to the best of my knowledge (if you specify the element-type, etc).

I usually don't code at that low level, but you might want to check out www.lrde.epita.fr/~didier/research/verna.06.imecs.pdf

Re: Make Lisp 15x faster than Python or 4x faster than Java

#19
I like the Lisp approach to optimize the program by adding hints to the runtime about types and the ability to tune the optimizer's aggressiveness from the code. It really makes possible to write the correct algorithms first, then later add appropriate optimizations simply by changing the optimized and unoptimized functions.

That said I think these kinds of benchmarks (and article titles) are misleading, because one who has deep knowledge in one language does not necessarily write good code in other languages. Even the article notes that "they are all just literal line-by-line translations of each other".

Re: Make Lisp 15x faster than Python or 4x faster than Java

#20
post #17

Any guesses as to why the Java implementation is relatively slow? JNI boundary crossings for floating point arithmetic, or lack of use of the math coprocessor?

I don't know, but it's much slower than I expected. It's the latest Java installable by apt on Debian (all these tests are run in Debian running under VMWare).

  $ java -version
  java version "1.6.0_0"
  OpenJDK  Runtime Environment (build 1.6.0_0-b11)
  OpenJDK 64-Bit Server VM (build 1.6.0_0-b11, mixed mode)
Post reply on HN