cout is too slow

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

cout is too slow

 
0
  #1
May 30th, 2006
I am extremely new to C++, can sum1 tell me a faster way to output stuff than cout? It either outputs too slow or takes too long to automatically scroll or something. I was trying to sort of output and refresh in real time w cout
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: cout is too slow

 
0
  #2
May 30th, 2006
Can you explain a bit more on what you are trying to do? Better if you can post the code. Otherwise there will be a lot of answers based on a lot of assumptions.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: cout is too slow

 
0
  #3
May 30th, 2006
its really big, prolly outside the limits for posts. Im getting way ahead of myself, making a program this big wen i know nothing and probably would be able to make the same program better if i wait until i know more. but, basically its a program for the 15 slider puzzle and it gets confusing/disorienting or watever cause the info is flashing too fast for you to really make moves as fsast as you would like.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: cout is too slow

 
0
  #4
May 30th, 2006
Wow, i need to read what I write before i post. If anyone wants, i can email it so you can see what i mean.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: cout is too slow

 
0
  #5
May 30th, 2006
No need to email. You can attach your program here. Make sure you attach code, and not the executable.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: cout is too slow

 
0
  #6
May 30th, 2006
Fancy. Ty. Its like 1008 lines and not well commented, though. Atleast it only uses simple stuff.
Attached Files
File Type: cpp 15puzzle.cpp (31.0 KB, 24 views)
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: cout is too slow

 
0
  #7
May 30th, 2006
Skimmed through your program, and it is not cout that seems to be the problem. You are calling cout too much. Remember that optimization of code should start first with your algorithm. The rest will usually be taken care by a decent compiler. Take for example the for loops where you are outputting 50 newline characters.
  1. for ( i = 0 ; i < 50; i++ )
  2. cout << '\n';
This piece of code calls cout 50 times. IO functions take a lot of time. That means you are writting to the console 50 times which takes a lot of time, when you consider the total number of times you do this in your program.
A better way will be to first create the string with 50 newline characters and output them all in a single cout call. like this

  1. std::string newline( 50, '\n');
  2. std::cout << newline ;
Clean up your code like that, and you will get to know more modifications where you can make the code fast.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: cout is too slow

 
0
  #8
May 30th, 2006
thanks. I don't know how to apply it, though.... Im new. I dont even know what std:: and that newline function do. (sry)
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: cout is too slow

 
0
  #9
May 30th, 2006
newline is not a function. It is a string object. What
std::string newline( 50, '\n' ) does is, create a string called newline that has 50, '\n' characters. Since you have used using namespace std; at the beginning, you can just use string newline(50, '\n' );. You will have to use the #include <string> at the beginning. Then cout just outputs it. I suggest you get a good C++ book if you dont have one, and start reading about C++ strings to learn more. you may fine good tutorials in the internet too.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: cout is too slow

 
0
  #10
May 30th, 2006
It's not a good idea to write a GUI in the console window.
You can do it of course, but you'll run into all sorts of problems.

If you have a java enabled browser this may give you some ideas as well.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC