C++ advice (scanf/printf)

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Aug 2005
Posts: 5,273
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: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: C++ advice (scanf/printf)

 
0
  #11
Mar 3rd, 2006
This thread is getting tedious, brahle you're talking out of your ****, learn some common sense then we might take notice. When is someone going to lock it up and throw it away, where it belongs. :rolleyes:
*Voted best profile in the world*
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,849
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 754
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: C++ advice (scanf/printf)

 
0
  #12
Mar 3rd, 2006
>When is someone going to lock it up and throw it away, where it belongs.
There's still hope, but I'll lock it when I feel that it needs to be locked. I won't throw it away because there's valuable information contained among the nonsense.
New members chased away this month: 4
Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: brahle is an unknown quantity at this point 
Solved Threads: 0
brahle's Avatar
brahle brahle is offline Offline
Newbie Poster

Re: C and C++ Timesaving Tips

 
0
  #13
Mar 3rd, 2006
Originally Posted by Narue
>Have you ever been to competitions?
Yes, and I adjust my code accordingly to conform to the rules. However, this is quite irrelevant to your faulty advice because 1) you're just plain wrong, and 2) most of the time, one is not writing code for a competition.

>I know that cin and cout ARE slower.
It depends on what you're testing. Obviously you aren't aware that cin and cout are fully functional objects with a great deal more power and flexibility than scanf and printf. If all you're doing is printing strings then I would expect a naive test to show printf to be faster. However, and this relies heavily on the quality of the implementation, on modern compilers with comparison code written by someone objective and knowledgeable, you won't see much difference in speed.

>You want proof, here it is.
Heh, what are you doing, timing it with a stopwatch? Give me your profiler's output, add some timing framework, or don't even waste my time with such a silly test. Oh, and if you're trying to prove something, give me details on your compiler and system.

Let's try this one instead. It's rough, and not entirely portable, but it should give you approximate times for your implementation. Mine shows comparable speeds where the difference varies between printf and cout, and the difference is negligable. That kind of flies in the face of your assertion, doesn't it?
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <ctime>
  4.  
  5. int main()
  6. {
  7. std::clock_t start1, start2;
  8. double diff1, diff2;
  9.  
  10. start1 = std::clock();
  11. for ( int i = 0; i < 100000; i++ )
  12. std::cout<<"a";
  13. diff1 = ( std::clock() - start1 ) / (double)CLOCKS_PER_SEC;
  14.  
  15. start2 = std::clock();
  16. for ( int i = 0; i < 100000; i++ )
  17. printf ( "a" );
  18. diff2 = ( std::clock() - start2 ) / (double)CLOCKS_PER_SEC;
  19.  
  20. std::cout<<"cout: "<< diff1 <<'\n'
  21. <<"printf: "<< diff2 <<'\n';
  22. }
>And do you know why?
Yes, I do. That makes one of us. :rolleyes:

>It is because cin and cout everytime have to get the type of the variable you are sending to them
When making a joke, it's customary to add the appropriate smiley. Otherwise I'd be inclined to think that you're spouting nonsense on a subject that you clearly know very little about. My only conclusion is that you're trying to be smart and failing miserably because you seem to be talking to someone who knows way more about C++ than you do.

>and scanf() and printf() from their prototype know what kind of variables to expect.
And in what way do you think that the runtime type selection from a format string with scanf/printf is faster than selecting an overloaded function at compile time?
Try writing a bigger constant, like 100,000,000.
Revenage is a dish best served cold.
50|2|2Y 4 |34|) 3|\|6|_|5|-|
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,849
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 754
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: C++ advice (scanf/printf)

 
0
  #14
Mar 3rd, 2006
>Try writing a bigger constant, like 100,000,000.
Try understanding the phrases "naive comparison" and "negligable difference". The first point concerns the fact that you're not using cout in a comparable way to what printf does, so the test is extremely biased in favor of printf. The second point concerns the fact that if you have to run the loop 100 million times to get any reasonable performance difference, the difference is so small as to be negligable. But I applaud your abundance of free time such that you could run the program with a loop constant of 100,000,000. :rolleyes:

Your initial advice is sound in the proper context, but you're lacking the proper context and trying feverishly to cover your ass after I repeatedly proved your claims incorrect. I highly recommend you quit while you're not too far behind, because it's painfully obvious that you're way out of your league in a technical debate with me on the details of C++.

By the way, I'm still waiting for your response to my other questions. Most notably this one:
Originally Posted by Narue
And in what way do you think that the runtime type selection from a format string with scanf/printf is faster than selecting an overloaded function at compile time?
And this one:
Originally Posted by Narue
Oh, and if you're trying to prove something, give me details on your compiler and system.
And out of sheer curiosity, this one:
Originally Posted by Narue
Heh, what are you doing, timing it with a stopwatch?
New members chased away this month: 4
Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
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: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: C++ advice (scanf/printf)

 
0
  #15
Mar 3rd, 2006
The thing which makes this thread amusing is that fact that you think using printf instead of cout, may save you time in a coding competition.

What competitions are you entering where such a ridiculous criterion is encouraged.

Don't you realise that these competitions are judged on the strength of the algorithm, and the ingenuity of the coder.
For example, using quicksort over bubble sort. Or applying a dynamic approach as opposed to a brute force one.

Please stop making me cringe with embarassment for you. :eek:
*Voted best profile in the world*
Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: C++ advice (scanf/printf)

 
0
  #16
Mar 3rd, 2006
what makes me wonder is what competition judge would give high marks for someone using C style (IO) routines in a C++ application where a C++ alternative is available.
Programming style is highly important in most competitions, and that's exceedingly poor style.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Quick reply to this message  
Join Date: Jun 2004
Posts: 192
Reputation: Toba is an unknown quantity at this point 
Solved Threads: 5
Toba's Avatar
Toba Toba is offline Offline
Junior Poster

Re: C++ advice (scanf/printf)

 
0
  #17
Mar 3rd, 2006
brahle, just give up. Narue knows her stuff. BTW Narue, did you give up on IRC?
what? WHAT?
Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C++ advice (scanf/printf)

 
2
  #18
Mar 3rd, 2006
Don't give up brahle! You'll just get used to always making sure you're not overgeneralizing, the way we all did when we slammed into Narue...
All my posts may be redistributed under the GNU Free Documentation License.
Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: C++ advice (scanf/printf)

 
0
  #19
Mar 3rd, 2006
I never overgeneralise (how's that for overgeneralisation ).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C++ advice (scanf/printf)

 
2
  #20
Mar 3rd, 2006
Yours doesn't count, because you spelled overgeneralize 'incorrectly'
All my posts may be redistributed under the GNU Free Documentation License.
Quick reply to this message  
Closed Thread

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




Views: 16367 | Replies: 39
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC