| Thread overview | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 13, 2008 Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Hi. I'm currently trying to convert my application to linux. Now I had a counter in my application that counted in milliseconds the time since the application started. I have to port this to linux. On windows I used the PerformanceCounter from the WinAPI (or the GetTickCount method, if the performance-counter is not supported). Well, I would like to have it more OS-independent or at least working somehow in linux. I tried the std.date, but actually I would have to calculate the ms-value up from the splitted values (hours, days, etc). That would be kinda complicated, cause there are too many special things. Like some month only have 30 days, sometimes 28, etc. Then I found the std.c.time clock() method, but realized, that that maybe wraps very early, cause one second is 1000000 and the value is stored in an integer. that would mean that after ~36 minutes the timer would wrap to zero (or minus something?) again. That's not helpful. So, now I'm looking for an alternate way to realize what I want. I just want ANY time counter in milliseconds. I can calculate it down to any base I want, but I just need a time~ Thanks in advance for any help | ||||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Schulte | Benjamin Schulte wrote:
> Hi.
> I'm currently trying to convert my application to linux.
> Now I had a counter in my application that counted in milliseconds the time since the application started. I have to port this to linux.
>
> On windows I used the PerformanceCounter from the WinAPI (or the GetTickCount method, if the performance-counter is not supported).
>
> Well, I would like to have it more OS-independent or at least working somehow in linux.
> I tried the std.date, but actually I would have to calculate the ms-value up from the splitted values (hours, days, etc). That would be kinda complicated, cause there are too many special things. Like some month only have 30 days, sometimes 28, etc.
> Then I found the std.c.time clock() method, but realized, that that maybe wraps very early, cause one second is 1000000 and the value is stored in an integer. that would mean that after ~36 minutes the timer would wrap to zero (or minus something?) again. That's not helpful.
>
> So, now I'm looking for an alternate way to realize what I want. I just want ANY time counter in milliseconds. I can calculate it down to any base I want, but I just need a time~
>
> Thanks in advance for any help
I quote from tools.time:
extern(C) {
struct timeval {
uint tv_sec;
int tv_usec;
}
int gettimeofday(timeval *, void *);
d_time µsec() {
timeval tv = void;
gettimeofday(&tv, null);
return tv.tv_sec*1_000_000 + tv.tv_usec;
}
}
Contrary to its name:
and gives the number of seconds and microseconds since the Epoch (see
time(2)).
--man gettimeofday
DESCRIPTION
time() returns the time since the Epoch (00:00:00 UTC, January 1,
1970), measured in seconds.
--man 2 time
Hope that answers your question.
--downs
| |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Schulte | "Benjamin Schulte" <Aldoric@gmx.de> wrote in message news:ftst9o$sql$1@digitalmars.com... > Hi. > I'm currently trying to convert my application to linux. > Now I had a counter in my application that counted in milliseconds the > time since the application started. I have to port this to linux. > > On windows I used the PerformanceCounter from the WinAPI (or the GetTickCount method, if the performance-counter is not supported). > > Well, I would like to have it more OS-independent or at least working > somehow in linux. > I tried the std.date, but actually I would have to calculate the ms-value > up from the splitted values (hours, days, etc). That would be kinda > complicated, cause there are too many special things. Like some month only > have 30 days, sometimes 28, etc. > Then I found the std.c.time clock() method, but realized, that that maybe > wraps very early, cause one second is 1000000 and the value is stored in > an integer. that would mean that after ~36 minutes the timer would wrap to > zero (or minus something?) again. That's not helpful. > > So, now I'm looking for an alternate way to realize what I want. I just want ANY time counter in milliseconds. I can calculate it down to any base I want, but I just need a time~ > > Thanks in advance for any help std.date.getUTCtime() gives you I believe millisecond-precise time as a long (64-bit int). | |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Schulte | Benjamin Schulte wrote: > On windows I used the PerformanceCounter from the WinAPI (or the > GetTickCount method, if the performance-counter is not supported). The last example shows how to access the hardware timer: http://www.digitalmars.com/techtips/timing_code.html | |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Benjamin Schulte wrote:
>> On windows I used the PerformanceCounter from the WinAPI (or the
>> GetTickCount method, if the performance-counter is not supported).
>
> The last example shows how to access the hardware timer:
>
> http://www.digitalmars.com/techtips/timing_code.html
What's up with std.perf? It's been in Phobos in "stealth mode" forever. Seems to work fine on Windows. Any chance it'll become official at some point? Why isn't it official now?
--bb
| |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> What's up with std.perf? It's been in Phobos in "stealth mode" forever. Seems to work fine on Windows. Any chance it'll become official at some point? Why isn't it official now?
Nobody has spent the time on it.
| |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Bill Baxter wrote:
>> What's up with std.perf? It's been in Phobos in "stealth mode" forever. Seems to work fine on Windows. Any chance it'll become official at some point? Why isn't it official now?
>
> Nobody has spent the time on it.
Well, what's missing?
Works fine on Windows, has lots of versions() for linux, so I assume it probably works there.
You just need someone to say that yeh, it tests out ok?
--bb
| |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | "Bill Baxter" <dnewsgroup@billbaxter.com> wrote in message news:ftts2j$2mom$1@digitalmars.com... > Walter Bright wrote: >> Bill Baxter wrote: >>> What's up with std.perf? It's been in Phobos in "stealth mode" forever. Seems to work fine on Windows. Any chance it'll become official at some point? Why isn't it official now? >> >> Nobody has spent the time on it. > > Well, what's missing? > Works fine on Windows, has lots of versions() for linux, so I assume it > probably works there. > > You just need someone to say that yeh, it tests out ok? > > --bb AFAICT PerformanceCounter works fine on Linux. I've used it. | |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> AFAICT PerformanceCounter works fine on Linux. I've used it.
It also needs to be converted to ddoc.
| |||
April 13, 2008 Re: Get any time in milliseconds? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Jarrett Billingsley wrote:
>> AFAICT PerformanceCounter works fine on Linux. I've used it.
>
> It also needs to be converted to ddoc.
That's easy. I'll do that if you'll agree to put it in.
--bb
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply