Re: Commenting out a print slows my code?

2011-04-01 Thread vincent feltkamp
I managed to get the file, and even compile it, but apparently the type Ticks 
doesn't exists any more, it is now (DMD2.052)
TickDuration, with methods TickDuration.seconds (msecs, hnsecs, ...).

on my computer, it does not generate slower code without the writeln than with. 
( .38-.39 secs with, .37-.38 without)
am including the file as changed to make it work. It does vary a lot though: 
the first run after building takes .48 secs, the
next ones are in the ranges above. I guess it has more to do with priorities 
than with code efficiency.
begin 644 taxi.d
M:6UP;W)T('-T9"YD871E=&EM93L@+R\@9F]R('1H92!3=&]P5V%T8V@@PT*"6EN="!T87AI3G5M8F5R.PT*
M"6EN="!A+"!B+"!C+"!D.PD-"@ES=')I;F<@=&]3=')I;FPT*"0D)=W)I=&5L;BAC86))1"D[#0H)"7T-"@E]#0H)
M,R`](&X@/6->,R`K9%XS+B`-"BH@
M,RMY
M7C,@=V%S(&9O=6YD+"`-"BH@8R!A;F0@9"!W:6QL(&)E('IEF5R;R!A&D@;G5M8F5R+6YE&E#86(@:7-487AI*&EN="!N*7L-"@EI;G0@;&EM:70@/2!C=6)E4F]O
M=$9L;V]R*&XI("T@,3L-"@EI;G0@:&ETPT*"61O=6)L92!C
M=6)E4F]O="`](&X@7EX@*#$O,RXP*3L-"@EI;G0@8W)&;"`](&-A

Re: Commenting out a print slows my code?

2011-03-10 Thread spir

On 03/10/2011 01:44 AM, Charles McAnany wrote:

Hi, all. I'm in college, taking a freshman-level CS class. (I'm actually a
senior chemist with free time.)
Anyhoo, the warm-up assignment was Hardy Taxi problem, phrased like this:
[Exposition removed.] 1729 is the smallest number such that for
(a!=b!=c!=d)>0, there exists a combination of a, b, c, and d where a^3+b^3 =
1729 = c^3+d^3.
The task was to find all other numbers with this property less than 25,000.
The code is basically

for (int iters = 1; iters<= 25_000; iters++){
if(isTaxiNumber(iters)){
   writefln("%s is a taxi number", iters);
}
}

(There's also a StopWatch timing things, and isTaxiNumber returns a struct,
not a bool. See attached code.)
This code runs in about 0.09 seconds.
If I comment out the writefln, it takes 0.11 seconds.
(These are collected from about 20 runs of each. Times are very consistent.)
Any ideas why commenting out the write makes things slower?


No idea.

But more idiomatic D would rather b:
foreach (n ; 1..25000)
{...}

Also I don't understand why your loop var is called 'iters'.

Finally, the attachment is not readible by me: see below.

Denis


begin 644 taxi.d
M:6UP;W)T('-T9"YD871E=&EM93L@+R\@9F]R('1H92!3=&]P5V%T8V@@PT*"6EN="!T87AI3G5M8F5R.PT*
M"6EN="!A+"!B+"!C+"!D.PD-"@ES=')I;F<@=&]3=')I;F,RMB7C,@/2!N(#UC7C,@*V1>,RX@#0HJ(')E='5R;G,Z(`T*
M*B!A('1A>&E#86(@5XS('=APT*"0EI
M;G0@
M7B@Q+S,N,"D[#0H)"6EN="!N96%R97-T26YT(#T@8V%S="AI;G0I("AC=6)E
M4F]O="`K(#`N-2D[#0H)"61O=6)L92!D:69F(#T@*&-U8F52;V]T("T@;F5A
MPT*"0D):68@*&AI=',@/"`R("8F(')EPT*"0D)"7)E,R`\(&X@
M#0II;G0@8W5B95)O;W1&;&]O7B`H,2\S+C`I.PT*"6EN="!C

Re: Commenting out a print slows my code?

2011-03-09 Thread Jesse Phillips
Charles McAnany Wrote:

> (There's also a StopWatch timing things, and isTaxiNumber returns a struct,
> not a bool. See attached code.)
> This code runs in about 0.09 seconds.
> If I comment out the writefln, it takes 0.11 seconds.
> (These are collected from about 20 runs of each. Times are very consistent.)
> Any ideas why commenting out the write makes things slower?
> Cheers,
> Charles.

I couldn't get the code to compile with the stop watch. So instead I removed 
that and used time. In this case I get user times between .150 and .200 
approximately. Maybe with the print statement your program is given higher 
priority than without, that would mean the operating system would let your 
application run longer or more frequently than other programs (don't remember 
if one or both of those is changed).


Commenting out a print slows my code?

2011-03-09 Thread Charles McAnany
Hi, all. I'm in college, taking a freshman-level CS class. (I'm actually a
senior chemist with free time.)
Anyhoo, the warm-up assignment was Hardy Taxi problem, phrased like this:
[Exposition removed.] 1729 is the smallest number such that for
(a!=b!=c!=d)>0, there exists a combination of a, b, c, and d where a^3+b^3 =
1729 = c^3+d^3.
The task was to find all other numbers with this property less than 25,000.
The code is basically

for (int iters = 1; iters <= 25_000; iters++){
   if(isTaxiNumber(iters)){
  writefln("%s is a taxi number", iters);
   }
}

(There's also a StopWatch timing things, and isTaxiNumber returns a struct,
not a bool. See attached code.)
This code runs in about 0.09 seconds.
If I comment out the writefln, it takes 0.11 seconds.
(These are collected from about 20 runs of each. Times are very consistent.)
Any ideas why commenting out the write makes things slower?
Cheers,
Charles.
begin 644 taxi.d
M:6UP;W)T('-T9"YD871E=&EM93L@+R\@9F]R('1H92!3=&]P5V%T8V@@PT*"6EN="!T87AI3G5M8F5R.PT*
M"6EN="!A+"!B+"!C+"!D.PD-"@ES=')I;F<@=&]3=')I;F,RMB7C,@/2!N(#UC7C,@*V1>,RX@#0HJ(')E='5R;G,Z(`T*
M*B!A('1A>&E#86(@5XS('=APT*"0EI
M;G0@
M7B@Q+S,N,"D[#0H)"6EN="!N96%R97-T26YT(#T@8V%S="AI;G0I("AC=6)E
M4F]O="`K(#`N-2D[#0H)"61O=6)L92!D:69F(#T@*&-U8F52;V]T("T@;F5A
MPT*"0D):68@*&AI=',@/"`R("8F(')EPT*"0D)"7)E,R`\(&X@
M#0II;G0@8W5B95)O;W1&;&]O7B`H,2\S+C`I.PT*"6EN="!C