C Program to Time Command using clock_gettime
In C/C++, we can use the clock_gettime method from time.h to get the Seconds and Nano Seconds. The following C runs the external command and measure the time difference:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
char buf[1024];
int j = 0;
for (int i = 1; i < argc; ++ i) {
size_t l = strlen(argv[i]);
strcpy(buf + j, argv[i]);
j += l;
buf[j ++] = ' ';
}
buf[j] = '\0';
struct timespec curTime, nowTime;
clock_gettime(CLOCK_REALTIME, &curTime);
system(buf);
clock_gettime(CLOCK_REALTIME, &nowTime);
long int secs = nowTime.tv_sec - curTime.tv_sec;
long int nsec = nowTime.tv_nsec - curTime.tv_nsec;
printf("s = %ld\nns = %ld\n", secs, nsec);
return 0;
}
Compiled with gcc:
$ gcc run.c -o run
And then, we can measure the time of a program (performance profiler):
$ ./run echo Hello, World!
Hello, World!
s = 0
ns = 1379618
--EOF (The Ultimate Computing & Technology Blog) --
Reposted to Blog
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^
NEW! Following my Trail (Upvote or/and Downvote)
Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com
My contributions
- Video Downloader
- Steem Blockchain Tools
- Free Cryptos API
- VPS Database
- Computing Technology Blog
- A few useless tools
- And some other online software/tools
- Merge Files/Videos
- LOGO Turtle Programming Chrome Extension
- Teaching Kids Programming - Youtube Channel and All Contents
Delegation Service
Important Update of Delegation Service!
Support me
If you like my work, please:
- Buy Me a Coffee, Thanks!
- Become my Sponsor, Thanks!
- Voting for me:
https://steemit.com/~witnesses type in justyy and click VOTE
- Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
- Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
- Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses
Well..!You have done "GOAT" on behalf of steemit media
Pls vigit my diary if you get time .
@justyy #affable #india
@justyy sir if you don't mind i have a asking..
Sir i have seen some user get 3.44$+ vote for 5000 delegation per day but i got 1.48$ highest for delegation 5050sp i am not clear here?
Can you clear me sir?
Actually i just invested after seen 3.44$+ for 5000 sp
i also invest more sp if i get 3.44$+. Now my target is 25k sp delegation but if i got 1.48 then nothing to say.
plz sir hope you clear me about it,thanks
set me a proxy?
How to do that? can you tell me @justyy sir?
https://steemyy.com/witness-voting/?witness=justyy&action=proxy
@justyy sir i have done
![Screenshot_20210722-175450_Chrome.jpg](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmYQTxDCRxKqXwfwLCggnr1Fsw8PuUMad9QyVkRmUPMVvP/Screenshot_20210722-175450_Chrome.jpg)
Hi @justyy i have done