<div dir="ltr"><div>import std.stdio;</div><div>import std.array: appender, array;</div><div>import std.algorithm : findSplit, splitter, joiner, canFind, map;</div><div>import std.typecons : tuple, Tuple;</div><div>import std.conv : to;</div><div>import std.range : dropOne, dropExactly, takeExactly, chain;</div><div><br></div><div>alias push_type = Tuple!(int, char[], int, bool, bool);</div><div>alias npush_type = Tuple!(char[], int, char[]);</div><div><br></div><div>void read_log(string filename) {</div><div> File file = File(filename, "r");</div><div> auto npushed = appender!(npush_type[])();</div><div> auto pushed = appender!(push_type[])();</div><div> foreach (line; file.byLine) {</div><div> if (auto findResult = line.findSplit(" SYNC_PUSH: ")) {</div><div> auto rel = findResult[2];</div><div> auto att = rel.splitter(" ");</div><div><br></div><div> auto firstVal = <a href="http://att.front.to">att.front.to</a>!int;</div><div> auto secondVal = att.dropExactly(2).takeExactly(2).joiner(" ").to!(char[]).dup;</div><div> auto thirdVal = att.dropExactly(5).<a href="http://front.to">front.to</a>!int;</div><div> auto fourthVal = findResult[2].canFind("PA-SOC_POP");</div><div> auto fifthVal = findResult[2].canFind("CU-SOC_POP");</div><div> pushed.put(tuple(firstVal, secondVal, thirdVal, fourthVal, fifthVal));</div><div> continue;</div><div> }</div><div> if (auto findResult = line.findSplit(" SOC_NOT_PUSHED: ")) {</div><div> auto leftPart = findResult[0].splitter(" ").dropExactly(2)</div><div> .takeExactly(2);</div><div> auto rightPart = findResult[2].splitter(" ").takeExactly(2);</div><div> auto firstVal = chain(leftPart.front, leftPart.dropOne.front).to!(char[]);</div><div> auto thirdVal = <a href="http://rightPart.front.to">rightPart.front.to</a>!(char[]).dup;</div><div> auto secondVal = <a href="http://rightPart.dropOne.front.to">rightPart.dropOne.front.to</a>!int;</div><div> npushed.put(tuple(firstVal, secondVal, thirdVal));</div><div> continue;</div><div> }</div><div> }</div><div> // Doing more stuff with these arrays later. For now, just printing lengths</div><div> writeln(npushed.data.length);</div><div> writeln(pushed.data.length);</div><div>}</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 9, 2017 at 12:01 PM, uncorroded via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Friday, 9 June 2017 at 08:58:38 UTC, Daniel Kozak wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There is no difference in speed because you do not process your data<br>
</blockquote>
lazily, so you make many allocations, so this is main reason why it is so slow. I could improve that, but I will need to see some example data, which you are trying to parse.<br>
<br>
But some rules,<br>
1.) instead of ~= you shoud use std.array.appender<br>
2.) instead of std.string.split you could use std.algorithm.splitter or<br>
std.algorithm.findSplit<br>
3.) instead of indexOf I would use std.algorithm.startsWith (in case it is<br>
on the begining of the line)<br>
</blockquote>
<br></span>
Thanks everyone for the tips.<br>
The log file itself is 52 MB but I have added a sample in pastebin ( <a href="https://pastebin.com/vj778PK4" rel="noreferrer" target="_blank">https://pastebin.com/vj778PK4</a> ). Will try the suggestions today evening.<br>
</blockquote></div><br></div>