<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 9, 2017 at 9:34 AM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi guys,<br>
<br>
I am a beginner in D. As a project, I converted a log-parsing script in Python which we use at work, to D. This link was helpful - ( <a href="https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/" rel="noreferrer" target="_blank">https://dlang.org/blog/2017/05<wbr>/24/faster-command-line-tools-<wbr>in-d/</a> ) I compiled it with dmd and ldc. The log file is 52 MB. With dmd (not release build), it takes 1.1 sec and with ldc, it takes 0.3 sec.<br>
<br>
The Python script (run with system python, not Pypy) takes 0.75 sec. The D and Python functions are here and on pastebin ( D - <a href="https://pastebin.com/SeUR3wFP" rel="noreferrer" target="_blank">https://pastebin.com/SeUR3wFP</a> , Python - <a href="https://pastebin.com/F5JbfBmE" rel="noreferrer" target="_blank">https://pastebin.com/F5JbfBmE</a> ).<br>
<br>
Basically, i am reading a line, checking for 2 constants. If either one is found, some processing is done on line and stored to an array for later analysis. I tried reading the file entirely in one go using std.file : readText and using std.algorithm : splitter for lazily splitting newline but there is no difference in speed, so I used the byLine approach mentioned in the linked blog. Is there a better way of doing this in D?<br><br>
</blockquote></div>There is no difference in speed because you do not process your data 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.</div><div class="gmail_extra"><br></div><div class="gmail_extra">But some rules,</div><div class="gmail_extra">1.) instead of ~= you shoud use std.array.appender</div><div class="gmail_extra">2.) instead of std.string.split you could use std.algorithm.splitter or std.algorithm.findSplit</div><div class="gmail_extra">3.) instead of indexOf I would use std.algorithm.startsWith (in case it is on the begining of the line)</div><div class="gmail_extra"><br></div></div>