FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std.date sample code for figuring elapsed time

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Fri Aug 27, 2004 11:06 am    Post subject: std.date sample code for figuring elapsed time Reply with quote

Hi Brad/jcc7,

Below is another example for the "Standard Library" section of the tutorial.

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

Code:

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;
}
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Fri Aug 27, 2004 11:47 am    Post subject: Reply with quote

Looks great!

http://www.dsource.org/tutorials/index.php?show_example=115
Back to top
View user's profile Send private message AIM Address
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Fri Aug 27, 2004 12:56 pm    Post subject: Reply with quote

Thanks for the feedback ... and all your efforts to help make D a success. I have been VERY impressed by the civility and helpfulness of the great majority of the people participating in D forums.

My way of learning a new language/tool is to put together a whole series of "bite sized" code snippets that focus just on the specific topic I'm trying to figure out. My experience is that many tutorials start off too complicated without appropriate "baby steps." Or that they have extraneous code.

With the idea that I may contribute more tutorial examples, any suggestions on how to improve the two you've seen? For example, I'm not sure my "coding standards" are all that standard. Also, I'm tempted to leave off all blank lines to get more code on a page, but perhaps that's ill advised? Perhaps the use of msleep was extraneous in the elapsed time example? Your input would be appreciated so any sample code I contribute can be the most useful ... and 'nip in the bud' some bad habits I may be getting into the habit of committing.

TIA,
Lynn A.
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Fri Aug 27, 2004 1:03 pm    Post subject: Reply with quote

Hi jcc7,

Thanks for posting the example ... you're good Smile

A nit ... the examples for the "Standard Library" are alphabetized, which is a nice touch. But ....... At some point, it might be helpful to others to alphabetized the sample code titles in the other subsections.

TIA,
Lynn A.
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sat Aug 28, 2004 12:58 am    Post subject: Reply with quote

Lynn wrote:
Thanks for the feedback ... and all your efforts to help make D a success. I have been VERY impressed by the civility and helpfulness of the great majority of the people participating in D forums.
I think we're a pretty friendly group. Often, people will lock horns, but it's seldom mean-spirited.

Lynn wrote:
My way of learning a new language/tool is to put together a whole series of "bite sized" code snippets that focus just on the specific topic I'm trying to figure out. My experience is that many tutorials start off too complicated without appropriate "baby steps." Or that they have extraneous code.
That's how I try to learn a language, too. The "fundamentals" category is based on the idea of baby steps.

Lynn wrote:
With the idea that I may contribute more tutorial examples, any suggestions on how to improve the two you've seen? For example, I'm not sure my "coding standards" are all that standard. Also, I'm tempted to leave off all blank lines to get more code on a page, but perhaps that's ill advised? Perhaps the use of msleep was extraneous in the elapsed time example? Your input would be appreciated so any sample code I contribute can be the most useful ... and 'nip in the bud' some bad habits I may be getting into the habit of committing.
I pretty just cut-and-pasted the examples, but it looked good to me. (They compile, right? Smile)

There are so many things that can be done in D that aren't demonstrated in the examples that I'm not worried too much about the formatting. If the style looks good to you, go with it. The existing examples aren't all in the same style anyway. Use as much whitespace as you like. That's what scrollbars are for.

Keep those examples coming (I appreciate any help I can get)...
Back to top
View user's profile Send private message AIM Address
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sat Aug 28, 2004 1:07 am    Post subject: Reply with quote

Lynn wrote:
A nit ... the examples for the "Standard Library" are alphabetized, which is a nice touch. But ....... At some point, it might be helpful to others to alphabetized the sample code titles in the other subsections.
I could alphabetize everything, but actually I was trying to sort them from easier at the top to more difficult at the bottom (except I guess I decided to alphabetize one category). Maybe I'll add a button that changes the list to alphabetized or even add a search function. It kind of depends on whether I get bored with whatever else I'm working on. Razz

Since the examples are stored in a database, I have a lot of opportunity to play with things, but I've been complecent recently. Very Happy
Back to top
View user's profile Send private message AIM Address
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Sep 23, 2004 5:45 pm    Post subject: Reply with quote

I did some further looking, and came across:
std.perf.HighPerformanceCounter

Here is replacement code for the tutorial, or a different tutorial:
Code:

import std.stdio;
import std.c.time;
import std.perf;

void main ()
{
  HighPerformanceCounter hpc = new HighPerformanceCounter();
  hpc.start();

  // Code to be timed goes here ... just msleep for 1.2 seconds
  std.c.time.msleep(1200);

  hpc.stop();
  writefln("hpc ms: ", hpc.microseconds(),
              "  Seconds: ", hpc.microseconds() / 1000000.0);
}
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Thu Sep 23, 2004 8:38 pm    Post subject: std.perf Reply with quote

Lynn wrote:
Here is replacement code for the tutorial, or a different tutorial:
Thanks. I added it as std.perf.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group