These were the times on ubuntu 64 bit dmd. I added diamondShape, which is slightly modified to be consistent with the others .. just removing the second parameter and doing the writeln calls within the function, as the others have been done. This is still with dmd. I've downloaded ldc.

Also,  I posted the test code on dpaste.com/hold/1753517


brad: time: 20837[ms]
printDiamond1: time: 482[ms]
printDiamond2: time: 944[ms]
printDiamond3: time: 490[ms]
jay1: time: 62[ms]
sergei: time: 4154[ms]
jay2: time: 30[ms]
diamondShape: time: 3384[ms]

void diamondShape(in int N)
{
    import std.range : chain, iota, repeat;
    import std.algorithm : map;
    import std.conv : text;
    import std.string : center, format;
    import std.exception : enforce;
    dchar fillChar = '*';
    enforce(N % 2, format("Size must be an odd number. (%s)", N));

    foreach(ln;
                        chain(iota(1, N, 2),
                                  iota(N, 0, -2))
                        .map!(i => fillChar.repeat(i))
                        .map!(s => s.text)
                        .map!(s => s.center(N))) writeln(ln);
}

Reply via email to