View previous topic :: View next topic |
Author |
Message |
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Fri Aug 27, 2004 11:06 am Post subject: std.date sample code for figuring elapsed time |
|
|
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
|
Back to top |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Fri Aug 27, 2004 12:56 pm Post subject: |
|
|
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 |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Fri Aug 27, 2004 1:03 pm Post subject: |
|
|
Hi jcc7,
Thanks for posting the example ... you're good
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Sat Aug 28, 2004 12:58 am Post subject: |
|
|
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? )
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Sat Aug 28, 2004 1:07 am Post subject: |
|
|
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.
Since the examples are stored in a database, I have a lot of opportunity to play with things, but I've been complecent recently. |
|
Back to top |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Thu Sep 23, 2004 5:45 pm Post subject: |
|
|
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Thu Sep 23, 2004 8:38 pm Post subject: std.perf |
|
|
Lynn wrote: | Here is replacement code for the tutorial, or a different tutorial: | Thanks. I added it as std.perf. |
|
Back to top |
|
|
|
|
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
|