automate tuple creation

forkit forkit at gmail.com
Fri Jan 21 05:59:38 UTC 2022


On Friday, 21 January 2022 at 04:08:33 UTC, forkit wrote:
>
> // --
>
> void ProcessRecords
> (in int[][int][] recArray, const(string) fname)
> {
>     auto file = File(fname, "w");
>     scope(exit) file.close;
>
>     Appender!string bigString = appender!string;
>     bigString.reserve(recArray.length);
>     debug { writefln("bigString.capacity is %s", 
> bigString.capacity); }
>
>     void processRecord(const(int) id, const(int)[] values)
>     {
>         bigString ~= id.to!string ~ values.format!"%(%s,%)" ~ 
> "\n";
>     }
>
>     foreach(ref const record; recArray)
>     {
>         foreach (ref rp; record.byPair)
>         {
>             processRecord(rp.expand);
>         }
>     }
>
>     file.write(bigString[]);
> }
>
> // ---

actually something not right with Appender I think...

100_000 records took 20sec (ok)


1_000_000 records never finished - after 1hr/45min I cancelled 
the process.

??


More information about the Digitalmars-d-learn mailing list