OT (partially): about promotion of integers
deadalnix
deadalnix at gmail.com
Wed Dec 12 16:01:59 PST 2012
On Wednesday, 12 December 2012 at 23:47:26 UTC, Walter Bright
wrote:
> On 12/12/2012 3:23 PM, Timon Gehr wrote:
>> On 12/12/2012 10:35 PM, Walter Bright wrote:
>>> some algorithms are doomed to be slower.
>>
>> Here's a (real) quicksort:
>> http://stackoverflow.com/questions/5268156/how-do-you-do-an-in-place-quicksort-in-haskell
>
> Ok, I'll bite.
>
> Here's a program in Haskell and D that reads from standard in,
> splits into lines, sorts the lines, and writes the result the
> standard out:
>
> ==============================
> import Data.List
> import qualified Data.ByteString.Lazy.Char8 as L
> main = L.interact $ L.unlines . sort . L.lines
> ==============================
> import std.stdio;
> import std.array;
> import std.algorithm;
> void main() {
> stdin.byLine(KeepTerminator.yes)
> map!(a => a.idup).
> array.
> sort.
> copy(
> stdout.lockingTextWriter());
> }
> ===============================
>
> The D version runs twice as fast as the Haskell one. Note that
> there's nothing heroic going on with the D version - it's
> straightforward dumb code.
You'll find a lot of trap into that in D, some that can kill your
perfs. For instance :
stdin.byLine(KeepTerminator.yes).
map!(a => a.idup).
filter!(a => a).
array
And bazinga, you just doubled the number of memory allocation
made.
More information about the Digitalmars-d
mailing list