472,353 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Console.Writeline in release builds a performance issue ?

Hi

Can a lot of Console.Writeline commands cause a program to run slower ?

johan

Nov 23 '05 #1
5 5141
The short answer is I don't know. But why dont you try looping over 1
million times doing Console.Writeline and see how long it takes. If it
takes 1 second or less (dont run it under debug mode) then theres really
no point going round commenting out all the references in your code.

Instead, why not define a DEBUG symbol and only include it in debug
builds. eg
#if DEBUG
Console.Writeline("This is a debug only statement");

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #2
I couldn't help myself...

DateTime start = DateTime.Now;
for(int i=0;i<1000000;i++)
Console.WriteLine("hello there");

StreamWriter writer = new StreamWriter("time.txt");
string line = "time=" + (DateTime.Now.Ticks-start.Ticks)/10000 +
"ms";
writer.WriteLine(line);
writer.Close();

Takes about 500ms on my machine (2.8Ghz nothing special)

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #3
An easier way rather than putting lots of #if DEBUG all over your code is to
use either the:

System.Diagnostics.Debug.WriteLine or
System.Diagnostics.Trace.WriteLine methods

When in debug mode both Trace and Debug will output, when in release only
trace will output, unless you remove the TRACE symbol from you compiler
options.

Hope that helps.
Mark R Dawson
http://www.markdawson.org


"vooose" wrote:
The short answer is I don't know. But why dont you try looping over 1
million times doing Console.Writeline and see how long it takes. If it
takes 1 second or less (dont run it under debug mode) then theres really
no point going round commenting out all the references in your code.

Instead, why not define a DEBUG symbol and only include it in debug
builds. eg
#if DEBUG
Console.Writeline("This is a debug only statement");

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #4
Thanks

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
An easier way rather than putting lots of #if DEBUG all over your code is to use either the:

System.Diagnostics.Debug.WriteLine or
System.Diagnostics.Trace.WriteLine methods

When in debug mode both Trace and Debug will output, when in release only
trace will output, unless you remove the TRACE symbol from you compiler
options.

Hope that helps.
Mark R Dawson
http://www.markdawson.org


"vooose" wrote:
The short answer is I don't know. But why dont you try looping over 1
million times doing Console.Writeline and see how long it takes. If it
takes 1 second or less (dont run it under debug mode) then theres really
no point going round commenting out all the references in your code.

Instead, why not define a DEBUG symbol and only include it in debug
builds. eg
#if DEBUG
Console.Writeline("This is a debug only statement");

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #5
Sagaert Johan wrote:
Can a lot of Console.Writeline commands cause a program to run slower


Compared to what? Not doing something will always be faster than doing
something.

--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 24 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future....
2
by: Franco, Gustavo | last post by:
Hi, Console.WriteLine does something on Release mode? I have many of them in my application and I want to know if the performace could be...
19
by: Jeff S | last post by:
Whenever I execute any Console commands (Console.WriteLine "yada yada yada"), the console does not appear. It doesn't even flash by. I want to be...
2
by: Steve | last post by:
I have created a console app that simply prints out a message a couple times, then exits, here is the code: <code> for(int i = 0; i < 10; i++) {...
0
by: Peteroid | last post by:
I use the Console for debug purposes, so I created my application as a Console project. I create my own custom Form class, so I don't want to use a...
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts...
2
by: Wayne Sepega | last post by:
We are currently having an issue with one of our web applications. Some users receive an exception when using the app, but the method that has the...
4
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
does this command use a lot of resources? should i comment them all out before creating my .exe file? i use it a lot for debugging... or, does it...
3
by: Bob Johnson | last post by:
It is my understanding - and please correct me if I'm wrong - that when building a project in debug mode, I can deploy the .pdb file along with the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.