News for hackers. Stuff that matters.
Re:When Haskell is Faster than C by jacquesm on Friday January 18, 2013 @04:04PM (#5081006)
Ok, I pledge to re-write this properly and to benchmark the current implementation vs a nice one. I'll post the results. I need something to get my mind off things and this is as good as any. It will take at least until Monday (it is my sons birthday tomorrow).
Re:When Haskell is Faster than C by ay on Friday January 18, 2013 @07:30PM (#5082001)
Hey Jacques, may ask for a code review ? :-)

http://stdio.be/revseq.c

Compiled with "gcc -pipe -Wall -O3 -fomit-frame-pointer -std=c99 -pthread" on my Mac, it's about twice as fast at the blog author's version.

Time spent: coding: 30 minutes bugfixing: 30 minutes

I have a feeling there is some kind of catch in the description of the algorithm in terms of implementing the output, but I for the life of me could not grok whether they wanted me to parse the entry into these three pieces or not...

EDIT to add: The only optimization I made was inlining the tightly-called "subst" function, did it without any profiling (so the optimization process literally took about 30 seconds:). Before inlining this version was still about 15% faster than the blog author's one.

Re:When Haskell is Faster than C by jacquesm on Friday January 18, 2013 @07:41PM (#5082040)
Sure, I'll pick it up in the post. Neat little project this. I won't peek at your code until I'm done.
Re:When Haskell is Faster than C by ay on Saturday January 19, 2013 @08:02AM (#5083267)
Thank you! It was indeed a nice little fun exercise. It is interesting the bugs that I made by being tired and not reading the task carefully/not thinking clearly (yesterday was a bit of a long and stressy day):

1) My initial understanding was that I do need to reverse the order, yet somehow after re-reading the article I understood the order does not need to change, and the "reverse" in the name is some kind of jargon. This is quite stupid, and probably not worth mentioning, if only to prove I was tired :)

2) missing that the first iteration of the "business logic" code in my case happens before anything is filled in. Crash.

3) forgetting about the "\n"s - with rather funny "partially correct" output effect.

Very much looking forward to see your code !

Re:When Haskell is Faster than C by jacquesm on Sunday January 20, 2013 @09:54PM (#5089569)
Hey Andrew,

Ok, I looked at your code. What you really should do (before coding up the solution) is to look at the problem specification. Other than that I like the 'direct' approach, it isn't quite as fast as what I cooked up but yours is a lot shorter.

Re:When Haskell is Faster than C by ay on Monday January 21, 2013 @11:23AM (#5092101)
Thanks! yes, this goes to show the perils of coding after a 12h work day on Friday :-). This affected the use of fgets() I/O (I understood you have to call the line-buffered routines based on their description)

Enjoyed reading your code. Beautiful. Thanks!

Re:When Haskell is Faster than C by decad on Friday January 18, 2013 @04:14PM (#5081070)
Looking forward to seeing your results from this.
Re:When Haskell is Faster than C by michaelkscott on Friday January 18, 2013 @05:56PM (#5081582)
Seconded. How are you going to be posting it?
Re:When Haskell is Faster than C by jacquesm on Friday January 18, 2013 @06:12PM (#5081668)
Blog entry, already working on it. It's fun.
Re:When Haskell is Faster than C by Xcelerate on Saturday January 19, 2013 @01:56AM (#5082846)
Be sure to post it as a HN submission when you finish!
Re:When Haskell is Faster than C by zxcdw on Friday January 18, 2013 @04:14PM (#5081072)
Subscribing to this.