Earlier quoted context omitted.
Incorrect code is silly. It is not unlikely that the different languages are performing a different number of iterations in these tests, correcting that by being precise about the range to be iterated over is not silly. The integer indices here produce the behavior that seems to be intended by the ` The speed difference is negligible since all but the inner multiplication is hoisted out, and each inner loop takes ove…
The speed difference is hardly negligible especially when talking about benchmarks. It's actually about 15% on my OS X laptop, less but still measurable on a Linux server. Your change actually has a greater impact on execution time than off-by-ones in the iteration counts which don't really take place.
Make Lisp 15x faster than Python or 4x faster than Java
71–80 of 100 posts
Re: Make Lisp 15x faster than Python or 4x faster than Java
#72The result of the distance() function is unused and can be optimized away by the compiler. Runs in 0.04s with LuaJIT 2.0. No type declarations needed. :-) local radius = 6371 local function distance(latA, lngA, latB, lngB) local latAr = math.rad(latA) local lngAr = math.rad(lngA) local latBr = math.rad(latB) local lngBr = math.rad(lngB) local deltaLat = latBr - latAr local deltaLng = lngBr - lngAr return radius * 2 *…
Re: Make Lisp 15x faster than Python or 4x faster than Java
#73Earlier quoted context omitted.
1. There is no C function. What do you call public static float distance(float latA, float lngA, float latB, float lngB) { As I said but that's not a huge deal. Yes it's not a major slowdown, but a tight inner loop with a function call is begging for an inline.
> import java.util.Calendar; might be your first clue... > but a tight inner loop with a function call is begging for an inline. The loop body makes several other function calls, you would be very hard pressed to measure the difference. And if it was a C function in a larger project, you probably wouldn't want to inline it because that would slow your compile times and cause you to lose modularity (i.e. you'd have to…
Re: Make Lisp 15x faster than Python or 4x faster than Java
#74The result of the distance() function is unused and can be optimized away by the compiler. Runs in 0.04s with LuaJIT 2.0. No type declarations needed. :-) local radius = 6371 local function distance(latA, lngA, latB, lngB) local latAr = math.rad(latA) local lngAr = math.rad(lngA) local latBr = math.rad(latB) local lngBr = math.rad(lngB) local deltaLat = latBr - latAr local deltaLng = lngBr - lngAr return radius * 2 *…
Ha.. of course, the real problem is that Java and Python are actually doing all of the work to compute their trigonometric functions, while C libraries that Lisp uses probably have them mapped into a table. Java does actually keep a table for trig functions on small values -- they just haven't widened the table definition, which is filed as a bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5005861 "I just p…
Java and Python are actually doing all of the work to compute their
trigonometric functions
Not true in the case of CPython. It uses the underlying C implementation. See line 270 onwards.http://www.google.com/codesearch/p?hl=en#2T6lfGELm_A/trunk/M...
Re: Make Lisp 15x faster than Python or 4x faster than Java
#75http://t-b-o-g.blogspot.com/2009/12/brians-brain-on-common-l...
It highlights the importance of profiling code first.
Re: Make Lisp 15x faster than Python or 4x faster than Java
#76I ran the Python script through Shedskin, a partial Python implementation that compiles Python to machine code via an intermediate layer of C++. I did not have to declare any types for any variables, or add declarations for speed/safety; Shedskin automatically determined the types. The finished program went down in runtime from 533.7s on my machine, to 24.42 seconds. If we adjust for machine speed (since the author's…
And the project: http://code.google.com/p/shedskin/
Re: Make Lisp 15x faster than Python or 4x faster than Java
#77Earlier quoted context omitted.
Ha.. of course, the real problem is that Java and Python are actually doing all of the work to compute their trigonometric functions, while C libraries that Lisp uses probably have them mapped into a table. Java does actually keep a table for trig functions on small values -- they just haven't widened the table definition, which is filed as a bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5005861 "I just p…
Java and Python are actually doing all of the work to compute their trigonometric functions Not true in the case of CPython. It uses the underlying C implementation. See line 270 onwards. http://www.google.com/codesearch/p?hl=en#2T6lfGELm_A/trunk/M...
Re: Make Lisp 15x faster than Python or 4x faster than Java
#78Re: Make Lisp 15x faster than Python or 4x faster than Java
#79Any 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)
Plain vanilla use of Math.sin and Math.cos = 9.15s Constrain to the range +45 to -45 degrees = 4.88s
As demonstrated 20 months ago http://shootout.alioth.debian.org/gp4/program.php?test=parti...
Re: Make Lisp 15x faster than Python or 4x faster than Java
#80The result of the distance() function is unused and can be optimized away by the compiler. Runs in 0.04s with LuaJIT 2.0. No type declarations needed. :-) local radius = 6371 local function distance(latA, lngA, latB, lngB) local latAr = math.rad(latA) local lngAr = math.rad(lngA) local latBr = math.rad(latB) local lngBr = math.rad(lngB) local deltaLat = latBr - latAr local deltaLng = lngBr - lngAr return radius * 2 *…
Ha.. of course, the real problem is that Java and Python are actually doing all of the work to compute their trigonometric functions, while C libraries that Lisp uses probably have them mapped into a table. Java does actually keep a table for trig functions on small values -- they just haven't widened the table definition, which is filed as a bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5005861 "I just p…
http://shootout.alioth.debian.org/gp4/program.php?test=parti...