The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Legitimate uses of micro-benchmarks: parameter passing and function call costs

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Legitimate uses of micro-benchmarks: parameter passing and function call costs Posted: Nov 30, 2007 5:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Legitimate uses of micro-benchmarks: parameter passing and function call costs
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

So, everybody knows about the Fibonacci pissing contest by now. From the moment you mention two programming languages, this is likely to happen, and the blog post that triggered all this provided a small push sufficient to make the discussion degenerate that way*1. The chosen micro-benchmark also played a very negative role, as it gives too many opportunities to get sidetracked: better algorithms (recursion vs. iteration, memoization...), overflowable ints vs. arbitrary precision integers, etc.

You're probably expecting me to throw some code at you (OCaml since I've been talking about it a bit as of late) in spite of everything I wrote above and give enough figures to be able to claim something like "Holy Shmoly, OCaml smokes {Haskell, SBCL, C++} away". (That's truly a blogging classic, deploring the silliness of the latest blog trend and adding to it the second after.)

Instead, I'm going to use this micro-benchmark the way it was meant to: not to compare language implementations in general, but to measure an isolated characteristic. Micro-benchmarks are exceedingly useful for language implementors and for those who want to assess the cost of some particular operation.

What I want to do is build some intuition about the cost of function calls and argument passing in Haskell. I shall look at the generated assembly code in order to understand where my CPU cycles are going (this is where I'll be needing your help, because, as you will see, Haskell's asm isn't exactly easy to read).

Before I plunge into Haskell, I'll take a look at the code generated by GCC and OCaml, which will serve as the control group of sorts and help me verify that what I think I know about them is correct. If I can't understand what's going on with C and OCaml, I have no chance with Haskell. (Yes, I will also give you execution times, but I promise there will be no Holy Shmoly.)

Some familiar code first

This is what I expect in my first runs:

  1. argument passing should be faster in OCaml than in C with a non-static function
  2. GCC should be able to generate code about as fast (or faster) given enough inlining (OCaml never inlines recursive functions, recent GCC versions do)
  3. when using a static function (so that arguments are passed in registers instead of via the stack as required by the standard ABI), GCC's code should be as fast or faster than OCaml's

You can jump to the next section if you're not interested in the details of the code generated by GCC and OCaml. In few words, my intuition regarding C and OCaml was basically correct, and I now want to see what causes the Haskell figures in this table (this is where I'll need some help):

implementationexecution time(s)
GCC -O20.444
GCC -O30.405
OCaml0.413
Haskell (Int)1.03

Here goes the OCaml code and the corresponding assembly, which can hardly get more readable:


Read more...

Read: Legitimate uses of micro-benchmarks: parameter passing and function call costs

Topic: Twitter Updates for 2007-11-27 Previous Topic   Next Topic Topic: Rolling up my Sleeves, continued

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use