www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3741] New: std.date YearFromTime broken or very slow

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: steve.teale britseyeview.com



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: -------
Jan 25 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3741


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED



21:28:15 PDT ---
You can now use std.datetime.SysTime.year, as recommended in the "Migrating
from std.date to std.datetime" article that will be up on DPL.org soon.

import std.datetime;
auto year = (cast(DateTime)Clock.currTime()).year;

It takes 128 microseconds on my machine. Hope that's fast enough. Otherwise
file a bug report for std.datetime.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3741


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |



07:22:22 PDT ---
My mistake, this is D1. Reopened.

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