Login:
Pass:
Forgotten Pass?
Forums
Forum Home
Search
Today's Posts
Members List
Calendar




Search
Google
Search TBCS
Search the Web


Follow Us On




Go Back   TBCS Community Forums > Community Center > TBCS Challenges


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.
Reply
 
Thread Tools
  #91  
Old 04-27-2008, 05:00 PM
mtekk's Avatar
mtekk mtekk is offline
Posts: 469
Resident EE
 
mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.
My System
Default Re: Counting

Quote:
Originally Posted by Trace View Post
Wait, I think that's the one I entered. I'm not completely sure actually.
If that's the one you entered (the one in the count object, not the count2 object), then doing a similar thing in C++ results in times under the resolution of my timer, for all lengths.

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;
}
__________________
Quote:
Originally Posted by xRyokenx View Post
...I'm getting tired of not being able to figure this crap out because it's apparently made for computer-illiterate people by computer-illiterate people. lol
Reply With Quote
  #92  
Old 04-28-2008, 04:18 AM
silverdemon's Avatar
silverdemon silverdemon is offline
Posts: 518
Water Cooled
 
silverdemon is a helpful and decent person.silverdemon is a helpful and decent person.silverdemon is a helpful and decent person.
My System
Default Re: Counting

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
as you can see the numbers are stored in an array. My program also had a display-button, that let's you display the numbers in the array (code not in here)

enjoy
Reply With Quote
  #93  
Old 04-28-2008, 04:38 AM
Helix666's Avatar
Helix666 Helix666 is offline
Posts: 425
You seem to be stood on my tail...
 
Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.
My System
Default Re: Counting

Quote:
Originally Posted by XcOM View Post
And helix, your app didn't have a counter and you didn't reply with a revision that did so, in efect your app does not have any scores becuase i couldn't get any.
*blink**blink*
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:
Originally Posted by gntlkilr
warranties are meant to be voided.

¤»Arty Stuffs. «¤|¤» My website. «¤
Reply With Quote
  #94  
Old 04-28-2008, 08:33 AM
mtekk's Avatar
mtekk mtekk is offline
Posts: 469
Resident EE
 
mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.
My System
Default Re: Counting

Quote:
Originally Posted by silverdemon View Post
ok, here is the snippet of code that does the counting in my VB6 program...
...as you can see the numbers are stored in an array. My program also had a display-button, that let's you display the numbers in the array (code not in here)

enjoy
Looks like VB6's arrays are faster on small numbers than C++ vectors (vector class objects) and C dynamically allocated arrays (using malloc()). That is interesting.
__________________
Quote:
Originally Posted by xRyokenx View Post
...I'm getting tired of not being able to figure this crap out because it's apparently made for computer-illiterate people by computer-illiterate people. lol
Reply With Quote
  #95  
Old 04-28-2008, 12:47 PM
XcOM's Avatar
XcOM XcOM is offline
Posts: 2,931
Ceann na Drochaide Bige!
 
XcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder SupremeXcOM Modder Supreme
My System
Default Re: Counting

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
__________________


Mary had a little lamb. It bumped into a pylon. Ten thousand volts went up its arse and turned its wool to nylon!
Reply With Quote
  #96  
Old 04-28-2008, 07:19 PM
Helix666's Avatar
Helix666 Helix666 is offline
Posts: 425
You seem to be stood on my tail...
 
Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.Helix666 knows what they are talking about when it comes to computers.
My System
Default Re: Counting

XcOM: you did run it from a terminal/command prompt, right?

Code:
#include 
#include 
#include 

using namespace std;
int main(int argc, char *argv[]){
int count;
time_t timeAtStart, timeAtEnd;
if(argc>1)
	count = atoi(argv[1]);
else
	count=1e9;
unsigned long int ulNumber=0;
time( &timeAtStart );
cout << "Time at start: " << timeAtStart << endl;
ofstream fout("out.txt");
for(ulNumber=1;ulNumber<(count+1);ulNumber++){
fout << ulNumber << "\n";
}
fout.close();
time( &timeAtEnd);
cout << "Time at end: " << timeAtEnd << endl;
cout << "Time Taken: " << timeAtEnd - timeAtStart << " seconds." << endl;
return 0;
}
not pretty, but works. ah well, nevermind.
__________________
Quote:
Originally Posted by gntlkilr
warranties are meant to be voided.

¤»Arty Stuffs. «¤|¤» My website. «¤
Reply With Quote
  #97  
Old 04-28-2008, 09:43 PM
mtekk's Avatar
mtekk mtekk is offline
Posts: 469
Resident EE
 
mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.
My System
Default Re: Counting

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.
__________________
Quote:
Originally Posted by xRyokenx View Post
...I'm getting tired of not being able to figure this crap out because it's apparently made for computer-illiterate people by computer-illiterate people. lol
Reply With Quote
  #98  
Old 04-29-2008, 12:34 AM
Trace's Avatar
Trace Trace is offline
Posts: 2,059
Overclocking Guru
 
Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.Trace knows almost everything about modding.
My System
Default Re: Counting

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
Would work better because it doesn't have to check the value everytime, because it is set to run a specific number of times. My 2-bits
__________________
Quote:
Originally Posted by Lothair View Post
I guess it's just widely used and has had some of the best people in the world work on it, costing a ridiculous amount of money, for no actual reason. :/
Have you checked out the front page lately?
Projects:
Moe's Tavern | Sponsored by: Mimo Monitors, Crucial, Thermaltake
Book Of Knowledge
Reply With Quote
  #99  
Old 04-29-2008, 03:23 AM
silverdemon's Avatar
silverdemon silverdemon is offline
Posts: 518
Water Cooled
 
silverdemon is a helpful and decent person.silverdemon is a helpful and decent person.silverdemon is a helpful and decent person.
My System
Default Re: Counting

Quote:
Originally Posted by mtekk View Post
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...
That's true. I wanted to make the program as fast as I could, so I got every bit of code outside of the loop. Only the real counting takes place inside the loop. This way the loop will be smaller and since it'll be looped like 1mil or 1bil times every line of code and even every character on the line inside the loop will take a lot of time in the eventual program.

Trace: congrats on the win! +rep is on the way
Reply With Quote
  #100  
Old 04-29-2008, 08:46 AM
mtekk's Avatar
mtekk mtekk is offline
Posts: 469
Resident EE
 
mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.mtekk knows almost everything about modding.
My System
Default Re: Counting

Quote:
Originally Posted by silverdemon View Post
...This way the loop will be smaller and since it'll be looped like 1mil or 1bil times every line of code and even every character on the line inside the loop will take a lot of time in the eventual program...
You mean every instruction, characters are 'free', the number of instructions is what is important.

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--);
would produce more or less the same assembly as:
Code:
while(count)
{
count = count - 1;
}
or
Code:
while(count)
{
count -= 1;
}
or
Code:
while(count)
{
count--;
}
meaning they all will take the same amount of time to complete, unless you use an optimizing compiler that will say, well count just ends up going to zero, so let's skip the loop and just set it to zero.
__________________
Quote:
Originally Posted by xRyokenx View Post
...I'm getting tired of not being able to figure this crap out because it's apparently made for computer-illiterate people by computer-illiterate people. lol
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump

Translate This Page

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
thebestcasescenario.com