http://d.puremagic.com/issues/show_bug.cgi?id=3741

           Summary: std.date YearFromTime broken or very slow
           Product: D
           Version: 1.055
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: steve.te...@britseyeview.com


--- Comment #0 from Steve Teale <steve.te...@britseyeview.com> 2010-01-25 
04:57:11 PST ---
YearFromTime is used in several places in std.date.  If you run:

import std.stdio;
import std.date;
import std.c.linux.linux;

extern(C) int clock();

void main()
{
   int t1 = clock();
   int y;
   for (int i = 0; i < 100000; i++)
   {
      long t = getUTCtime();
      y = YearFromTime(t);
   }
   int t2 = clock();
   writefln("y = %d", y);
   writefln("elapsed %d", t2-t1);
   t1 = clock();
   for (int i = 0; i < 100000; i++)
   {
      int tt = time(null);
      tm *ptm = gmtime(&tt);
      y = ptm.tm_year+1900;
   }
   t2 = clock();
   writefln("y = %d", y);
   writefln("elapsed %d", t2-t1);
}

You will find that YearFromTime takes like 80 times longer. What's more calling
localtime gets you all the other stuff too.

It looks like it is approximating the year then doing some iterations to
check/adjust it, but the iterations are actually doing the whole job.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to