www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: tolf and detab

reply bearophile <bearophileHUGS lycos.com> writes:
Andrej Mitrovic:

 Andrei used to!string() in an early example in TDPL for some line-by-line
 processing. I'm not sure of the advantages/disadvantages of to!type vs .dup.

I have modified the code: import std.stdio: File, writeln; import std.conv: to; int process(string fileName) { int total = 0; auto file = File(fileName); foreach (rawLine; file.byLine()) { string line = to!string(rawLine); total += line.length; } file.close(); return total; } void main(string[] args) { if (args.length == 2) writeln("Total: ", process(args[1])); } The run time is 1.29 seconds, showing this is equivalent to the idup. Bye, bearophile
Aug 08 2010
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
--90e6ba53a8c02a4ac3048d575d74
Content-Type: text/plain; charset=ISO-8859-1

What are you using to time the app? I'm using timeit (from the Windows
Server 2003 Resource Kit). I'm getting similar results to yours. Btw, how do
you use a warm disk cache? Is there a setting somewhere for that?


On Sun, Aug 8, 2010 at 11:54 PM, bearophile <bearophileHUGS lycos.com>wrote:

 Andrej Mitrovic:

 Andrei used to!string() in an early example in TDPL for some line-by-line
 processing. I'm not sure of the advantages/disadvantages of to!type vs

I have modified the code: import std.stdio: File, writeln; import std.conv: to; int process(string fileName) { int total = 0; auto file = File(fileName); foreach (rawLine; file.byLine()) { string line = to!string(rawLine); total += line.length; } file.close(); return total; } void main(string[] args) { if (args.length == 2) writeln("Total: ", process(args[1])); } The run time is 1.29 seconds, showing this is equivalent to the idup. Bye, bearophile

--90e6ba53a8c02a4ac3048d575d74 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable What are you using to time the app? I&#39;m using timeit (from the Windows = Server 2003 Resource Kit). I&#39;m getting similar results to yours. Btw, h= ow do you use a warm disk cache? Is there a setting somewhere for that?<br> <br><br><div class=3D"gmail_quote">On Sun, Aug 8, 2010 at 11:54 PM, bearoph= ile <span dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com">bearo= phileHUGS lycos.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quo= te" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204= , 204); padding-left: 1ex;"> Andrej Mitrovic:<br> <div class=3D"im"><br> &gt; Andrei used to!string() in an early example in TDPL for some line-by-l= ine<br> &gt; processing. I&#39;m not sure of the advantages/disadvantages of to!typ= e vs .dup.<br> <br> </div>I have modified the code:<br> <div class=3D"im"><br> import std.stdio: File, writeln;<br> </div>import std.conv: to;<br> <div class=3D"im"><br> int process(string fileName) {<br> =A0 =A0int total =3D 0;<br> <br> =A0 =A0auto file =3D File(fileName);<br> =A0 =A0foreach (rawLine; file.byLine()) {<br> </div> =A0 =A0 =A0 =A0string line =3D to!string(rawLine);<br> <div class=3D"im"> =A0 =A0 =A0 =A0total +=3D line.length;<br> =A0 =A0}<br> =A0 =A0file.close();<br> <br> =A0 =A0return total;<br> }<br> <br> void main(string[] args) {<br> =A0 =A0if (args.length =3D=3D 2)<br> =A0 =A0 =A0 =A0writeln(&quot;Total: &quot;, process(args[1]));<br> }<br> <br> <br> </div>The run time is 1.29 seconds, showing this is equivalent to the idup.= <br> <br> Bye,<br> <font color=3D"#888888">bearophile<br> </font></blockquote></div><br> --90e6ba53a8c02a4ac3048d575d74--
Aug 08 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Andrej Mitrovic:

 What are you using to time the app?

A buggy utility that is the Windows port of the GNU time command.
 Btw, how do you use a warm disk cache? Is there a setting somewhere for that?

If you run the benchmarks two times, the second time if you have enough free RAM and your system isn't performing I/O on disk for other purposes, then Windows keep essentially the whole file in a cache in RAM. On Linux too there is a disk cache. The HD too has a cache, so the situation is not simple and probably they are not fully under control of Windows. Bye, bearophile
Aug 08 2010
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
Andrej Mitrovic wrote:
 Btw, 
 how do you use a warm disk cache? Is there a setting somewhere for that?

Just run it several times until the times stop going down.
Aug 08 2010