![]() |
C++ Gurus, School Me :D
Hello all fellow programmers. I'm having a hard time understanding the "time.h" file and it's uses. Currently, I've got a project that is supposed to show the time difference between reading/writing from RAM and reading/writing from disk. My program already performs all 4 functions, I just have to use the "time.h" file to show how long it takes and display it in an external file. So how to you start and stop this "measure of time"? I understand how to convert the number of ticks over to seconds (duh) but I just don't understand how to start and stop timing each function. Can anyone please explain this to me in ENGLISH please? Thanks!
BTW, here were the notes I got on "time.h": Code:
|
Re: C++ Gurus, School Me :D
I'm not sure whether I understand your question, but if you want to measure time consumed by calling some function you can simply use the clock() function for it (as the example stated)
clock() returns number of ticks since the program started. So: 1. you store the no. of ticks before the function call beginTime = clock(); 2. call the function funcBlaBla(); 3. measure no. of ticks after the function returned .. functionTime = clock() - beginTime; ..and of course transfer the ticks into seconds .. also note that if you want to measure writing/reading performance of some device you should do it be writing and reading some larger amount of data ..not just few bytes (and there can be also differences in sequential access and random access but I that don't bother you right now :) ) |
Re: C++ Gurus, School Me :D
Thanks a lot man! It really helped. I've never used the "time.h" library before . . . Just as long as it can measure the time it takes to read/write from RAM and HDD, and display them out into an external file, I'm all good. Thanks again.
|
Re: C++ Gurus, School Me :D
I'd hate to make another thread but I have another question. CHAR ARRAYS.
So I need to make a char array in a struct and have it read in from a file. HEre is my code: Code:
struct myStruct |
Re: C++ Gurus, School Me :D
Note, I no longer own the domain stickit.nu, the site is now NSFW. This code may help you, I wrote it a while back for use with qmail in .qmail files for |condredirect I believe.
Code:
// Spamfilter by evilghostCode:
#Sample Deny Spamlist.txt |
Re: C++ Gurus, School Me :D
Hi six_storm
The problems with that code is that it isn't indented properly. That always ruins everything. :p Always check all your statements are terminated (;'s) and that all your functions have a return type specified. You also need to watch out for namespaces. Everything in the standard c++ libraries is in the std namespace. To use something from a namespace you just scope it by going std::ifstream for example. The below code is syntactically ok (well, it compiles at least) but all you have is an uninitialized array big enough to hold 60 pointers...where does the data streamed from the inFile go? Code:
#include <fstream> |
Re: C++ Gurus, School Me :D
Quote:
I'm just going to talk to my teacher today after class and maybe I'll get some help there. My assignment is already one day late lol. Thanks for the help though! |
Re: C++ Gurus, School Me :D
Ok, I got everything worked out. Now my problem is indentation. I'm supposed to take an input file and meet the following conditions when outputting to the screen and output.txt:
1) When a "{" passes thru, go to the next line and indent 6 spaces. 2) When a "}" passes thru, go to the next line and dedent 6 spaces. 3) If you have a nested or two "{", go to next line and indent 12 spaces. What I can't figure out is how can you tell your program where the end of the line is to "endl;". Any takers? TIA. |
Re: C++ Gurus, School Me :D
Quote:
http://pastebin.com/ (select c++ syntax highlighting for easier reading) |
Re: C++ Gurus, School Me :D
Quote:
syntax is getline(stream, string var); the function reads the entire line until '\n' is hit and puts it into the string variable (if i remember correctly '\n' is trunced from the end of the string, so you may or may not need to add it depending on formatting specs) |
Re: C++ Gurus, School Me :D
Quote:
|
| All times are GMT -5. The time now is 07:38 AM. |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2013, nV News.