Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Elapsed Time (uses std.date and std.c.time)

Part of StandardLibraryCategory

Description

Calculate elapsed time using std.date and std.c.time functions

Example

import std.stdio;
import std.date;
import std.c.time;

void main ()
{
  const int DelayMillis = 2000;
  printf("Test will run for about %d millis\n", DelayMillis);

  d_time startTime = std.date.getUTCtime();
  d_time curTime = startTime;
  d_time elapsed = 0;

  // Code to be timed goes here ... just spin with msleep
  while(elapsed < DelayMillis) {
    curTime = getUTCtime();
    elapsed = curTime - startTime;
    std.c.time.msleep(100);
  }
  printf("Ticks/Sec: %u\n", std.date.TicksPerSecond);
  printf("Start: %u\n", startTime);
  printf("Current: %u\n", curTime);
  printf("Elapsed: %u\n", elapsed);

  return 0;
}

Source

Contributed by Lynn.

Link http://www.dsource.org/tutorials/index.php?show_example=115
Posted by jcc7
Date/Time Wed Dec 15, 2004 2:31 pm