|
||||||
|
Welcome to the TBCS Community Forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
|
|
Thread Tools |
|
#91
|
||||
|
||||
|
Quote:
![]() Ok so if you compiler does any optimization you will see your times drop to 0ms if you never use the variable you assign to out of the loop. If you do use it out side of the loop you get times exactly matching Trace's times (at least on my laptop). What that means is that the Java compiler Trace used did not optimize as it should have (his should have resulted in 0ms for any input number). The Code I used to test this: Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
clock_t start, end, elapsed;
unsigned char foo;
long count(0), temp(0), temp2;
do
{
cout << "How many iterations do you want to do?\n";
cin >> temp;
count = ++temp;
start = clock();
while(count)
{
temp2 = count--;
}
end = clock();
elapsed = end - start;
cout << "For " << temp2 << " loops (count from 0 to " << temp - 1 << ")\n We took: " << elapsed << " ms\n"
<< "Would you like to run again?(y/n)\n";
cin >> foo;
}
while(foo == 'y');
return 0;
}
__________________
|
|
#92
|
||||
|
||||
|
ok, here is the snippet of code that does the counting in my VB6 program. There are also comments at the end of all lines (did that for XcOM so he could see what I was doing)
Code:
Private Sub cmdStart_Click() 'start button
lblStatus.BackColor = RGB(255, 0, 0) 'make statuslabel red
lblStatus.Caption = "Counting..." 'print busy text
DoEvents 'give windows time to do things (writing in the label)
x = 0 'set startpoint to 0
Finish = Val(txtFinish.Text) 'read endpoint from textbox
ReDim Numbers(1 To Finish) As Long 'ready the array for input
StartTime = timeGetTime 'read the time (starttime)
Do Until x = Finish 'count until x = finish (the number from the textbox)
x = x + 1 'add one to x
Numbers(x) = x 'store x in the array
Loop 'loop the counting
EndTime = timeGetTime 'when finished, get time again (endtime)
TimeTaken = EndTime - StartTime 'calculate time taken
lblStatus.BackColor = RGB(0, 255, 0) 'make statuslabel green and
lblStatus.Caption = "Done!, Numbers stored in array, idle" 'print done text
lblOutput.Caption = Finish & ": " & TimeTaken & "ms" 'print the result to the label
End Sub 'end counting sub
enjoy |
|
#93
|
||||
|
||||
|
Quote:
what? my last revision outputs the time it takes to run to stdout... and I have the sourcecode to prove it. (well, it's at home, but...)
__________________
Quote:
¤»Arty Stuffs. «¤|¤» My website. «¤ |
|
#94
|
||||
|
||||
|
Quote:
![]()
__________________
|
|
#95
|
||||
|
||||
|
i think the winners should be joint winners between
Silverdemon and Trace, and sorry helix, but when run yourapp it never displayed the output for me. my app when i factored it in never won a single catagory. also yes i ran each test 5 times and got an adverage, the specs were: AMD X2 Tk55 (1.8GHz Dual core) 1Gb RAM 80GB SATA HDD |
|
#96
|
||||
|
||||
|
XcOM: you did run it from a terminal/command prompt, right?
Code:
#include
__________________
Quote:
¤»Arty Stuffs. «¤|¤» My website. «¤ |
|
#97
|
||||
|
||||
|
Helix, you realize that writing directly to that file is going to really slow things down right?
A semi-faster way is to use a stream buffer, dump the numbers into it, and then at the end dump it to the file buffer. The fastest way is to use a vector or array to hold your data. And dump that to the file after you're done with the timed loop, both Silverdemon and I did that. Or you could do what trace did and not actually store the individual values. In which any good compiler will optimize the loop out of the assembly code. ![]()
__________________
|
|
#98
|
||||
|
||||
|
Well, apparently the Java compiler didn't lol.
And on the loops, I think that you would find a: Code:
For x = 1 to CountTo 'Loop Next x
__________________
Quote:
Projects: Moe's Tavern | Sponsored by: Mimo Monitors, Crucial, Thermaltake Book Of Knowledge |
|
#99
|
||||
|
||||
|
Quote:
Trace: congrats on the win! +rep is on the way |
|
#100
|
||||
|
||||
|
Quote:
Trace, Using a for statement is no faster than using any other loop, the condition to keep within the loop is always checked (unless the loop is unrolled by the compiler). Using something like: Code:
while(count--); Code:
while(count)
{
count = count - 1;
}
Code:
while(count)
{
count -= 1;
}
Code:
while(count)
{
count--;
}
__________________
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
|
|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.














A semi-faster way is to use a stream buffer, dump the numbers into it, and then at the end dump it to the file buffer. The fastest way is to use a vector or array to hold your data. And dump that to the file after you're done with the timed loop, both Silverdemon and I did that. Or you could do what trace did and not actually store the individual values. In which any good compiler will optimize the loop out of the assembly code. 
