Click here to Skip to main content
15,914,642 members
Home / Discussions / C#
   

C#

 
GeneralRe: maximum number of methods supported in C# class Pin
Ed.Poore2-Jul-07 6:28
Ed.Poore2-Jul-07 6:28 
JokeRe: maximum number of methods supported in C# class Pin
Luc Pattyn2-Jul-07 4:10
sitebuilderLuc Pattyn2-Jul-07 4:10 
GeneralRe: maximum number of methods supported in C# class Pin
vytheese2-Jul-07 5:20
professionalvytheese2-Jul-07 5:20 
AnswerMore than 5000... Pin
Sean Michael Murphy2-Jul-07 9:25
Sean Michael Murphy2-Jul-07 9:25 
GeneralRe: More than 5000... Pin
DavidNohejl2-Jul-07 9:36
DavidNohejl2-Jul-07 9:36 
GeneralRe: More than 5000... Pin
Martin#2-Jul-07 10:03
Martin#2-Jul-07 10:03 
GeneralRe: More than 5000... Pin
PIEBALDconsult2-Jul-07 11:56
mvePIEBALDconsult2-Jul-07 11:56 
GeneralRe: More than 5000... Pin
Sean Michael Murphy2-Jul-07 15:28
Sean Michael Murphy2-Jul-07 15:28 
dnh wrote:
No wonder, always use StringBuilder for string concatenation in a loop.


Hmmm. Interesting. When I originally undertook to code this snippet to try to figure an answer to this guys question, optimization was pretty far from my mind. I mean, I cranked the original bit of code out in 15 minutes (or so) and had originally coded it so the methods would be recreated every time. I took another 5 minutes and optimized it so that only 1 method (the new one) would have to be concatenated to the "guts", which was then stuck in between the fixed "header" and "footer" of the class.

It ran slowly, but I assumed that most of the overhead was in the actual code compilation (compiling classes of 15000 lines), and not a little bit of string concatenation. So I've re-written it using StringBuilder and timed both versions for 500 iterations. The original code did 500 iterations on my PC in 161.5222 seconds. This version:

C#
StringBuilder inner = new StringBuilder();
 
DateTime startTime = DateTime.Now;
   
for (Int32 i = 0; i < 500; i++) {
   inner.Append("      public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine +
                "         return 42;" + Environment.NewLine +
                "      }" + Environment.NewLine);
 
   StringBuilder code = new StringBuilder(pre);
   code.Append(inner);
   code.Append(post);
   cr = icc.CompileAssemblyFromSource(cp, code.ToString());
 
   if (cr.Errors.Count > 0)
      break;
 
   methodCount++;
 
   if (methodCount % 10 == 0)
      System.Console.WriteLine(methodCount.ToString());
}
 
TimeSpan ts = DateTime.Now - startTime;
 
System.Console.WriteLine(ts.TotalSeconds);
did it in 160.111. Much less that 1% slower.

Not a string concatenation to be found, except for the line joins.

Anything to add?

Thanks.
Sean
GeneralRe: More than 5000... Pin
DavidNohejl2-Jul-07 21:54
DavidNohejl2-Jul-07 21:54 
GeneralRe: More than 5000... Pin
PIEBALDconsult3-Jul-07 7:14
mvePIEBALDconsult3-Jul-07 7:14 
GeneralRe: More than 5000... Pin
DavidNohejl3-Jul-07 7:41
DavidNohejl3-Jul-07 7:41 
GeneralRe: More than 100000... Pin
vytheese2-Jul-07 23:16
professionalvytheese2-Jul-07 23:16 
GeneralRe: More than 100000... Pin
Sean Michael Murphy3-Jul-07 5:01
Sean Michael Murphy3-Jul-07 5:01 
GeneralRe: More than 5000... Pin
PIEBALDconsult3-Jul-07 7:37
mvePIEBALDconsult3-Jul-07 7:37 
GeneralMore than 1000000 [modified] Pin
PIEBALDconsult3-Jul-07 11:50
mvePIEBALDconsult3-Jul-07 11:50 
GeneralRe: More than 5000... Pin
Sean Michael Murphy4-Jul-07 18:36
Sean Michael Murphy4-Jul-07 18:36 
QuestionError in calling a webservice Pin
ramdil2-Jul-07 3:15
ramdil2-Jul-07 3:15 
AnswerRe: Error in calling a webservice Pin
leppie2-Jul-07 3:58
leppie2-Jul-07 3:58 
AnswerRe: Error in calling a webservice Pin
Vasudevan Deepak Kumar2-Jul-07 4:53
Vasudevan Deepak Kumar2-Jul-07 4:53 
QuestionCan't focus TextBox on TabPage Pin
Tavbi2-Jul-07 3:01
Tavbi2-Jul-07 3:01 
AnswerRe: Can't focus TextBox on TabPage Pin
Luc Pattyn2-Jul-07 3:20
sitebuilderLuc Pattyn2-Jul-07 3:20 
GeneralRe: Can't focus TextBox on TabPage Pin
Tavbi2-Jul-07 19:57
Tavbi2-Jul-07 19:57 
GeneralRe: Can't focus TextBox on TabPage Pin
Tavbi2-Jul-07 20:27
Tavbi2-Jul-07 20:27 
AnswerRe: Can't focus TextBox on TabPage Pin
originSH2-Jul-07 3:50
originSH2-Jul-07 3:50 
GeneralRe: Can't focus TextBox on TabPage Pin
Tavbi2-Jul-07 19:33
Tavbi2-Jul-07 19:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.