📜 ⬆️ ⬇️

.Net: Multithreading Costs

Recently I received a simple task: write a windows service to process user requests. The question of what these requests are and according to what protocol the service works is beyond the scope of this article. Another factor seemed to me more interesting. Is it multi-threaded to do request processing? On the one hand, sequential execution slows down information processing. On the other hand, the costs of creating and launching a stream may not be justified.
So, the initial data: 20 simplest requests per second (1200 requests per minute) at peak time. Test "server": Celeron, 3G, 1GB (70% free).

Single threaded system


First, we write a class base for single-threaded query execution.
using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  1. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  2. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  3. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  4. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  5. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  6. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  7. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  8. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  9. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  10. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  11. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  12. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  13. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  14. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  15. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  16. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  17. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  18. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  19. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  20. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  21. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  22. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  23. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  24. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  25. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  26. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  27. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  28. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  29. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  30. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  31. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  32. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  33. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  34. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  35. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  36. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  37. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  38. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  39. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  40. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  41. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  42. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  43. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  44. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  45. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
  46. using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .
using System; using System.Diagnostics; using System.Threading; namespace TestConsoleApplication { class mockClass { private readonly Int32 incriment_speed; private Int32 inc; public mockClass( int incriment_speed) { this .incriment_speed = incriment_speed; inc = 0; } public Int32 incriment() { Thread.Sleep(incriment_speed); return inc++; } public Int32 getIncriment() { return inc; } } class TestConsoleApplication { static void Main( string [] args) { if (args.Length<1) return ; Int32 mockSpeed = 0; if (! Int32 .TryParse(args[0], out mockSpeed)) return ; var mock = new mockClass(mockSpeed); int beginTick = Environment.TickCount; for ( int j = 0; j < 1200; j++) { mock.incriment(); } int endTick = Environment.TickCount; var performance = new PerformanceCounter( "Process" , "Private Bytes" , Process.GetCurrentProcess().ProcessName); Console .WriteLine(mock.getIncriment()); Console .WriteLine( "tick: {0}" , endTick - beginTick); Console .WriteLine( "memory: {0:N0}K" , (performance.RawValue/1024)); Console .ReadLine(); } } } * This source code was highlighted with Source Code Highlighter .

Run the program with several parameters for delaying the request: 2, 5, 10
2fiveten
tickmemorytickmemorytickmemory
368810 792K728110 780K1312510 792K

As you can see, the memory practically does not suffer, and the time is approximately equal to (mockSpeed ​​+ 1) * 1200. An extra millisecond will be written off for overhead.

Multithreaded system


Let's rewrite the program for working with multithreading, optimize it and check the results:
  1. using System;
  2. using System.Diagnostics;
  3. using System.Threading;
  4. namespace TestConsoleApplication
  5. {
  6. class mockClass
  7. {
  8. private readonly Int32 incriment_speed;
  9. private Int32 inc;
  10. public mockClass ( int incriment_speed)
  11. {
  12. this .incriment_speed = incriment_speed;
  13. inc = 0;
  14. }
  15. public Int32 incriment ()
  16. {
  17. Thread.Sleep (incriment_speed);
  18. return inc ++;
  19. }
  20. public Int32 getIncriment ()
  21. {
  22. return inc;
  23. }
  24. }
  25. class TestConsoleApplication
  26. {
  27. private static mockClass mock = null ;
  28. static void threadmethod ()
  29. {
  30. lock (mock)
  31. {
  32. mock.incriment ();
  33. }
  34. }
  35. static void Main ( string [] args)
  36. {
  37. if (args.Length <1) return ;
  38. Int32 mockSpeed ​​= 0;
  39. if (! Int32 .TryParse (args [0], out mockSpeed)) return ;
  40. mock = new mockClass (mockSpeed);
  41. var performance = new PerformanceCounter ( "Process" , "Private Bytes" , Process.GetCurrentProcess (). ProcessName);
  42. long performance_RawValue = 0;
  43. int beginTick = Environment.TickCount;
  44. lock (mock)
  45. {
  46. for ( int j = 0; j <1200; j ++)
  47. {
  48. var trd = new thread (threadmethod, 65536); // select 1 page per stack
  49. trd.Start ();
  50. }
  51. performance_RawValue = performance.RawValue;
  52. }
  53. int end1Tick = Environment.TickCount;
  54. while (mock.getIncriment () <1200)
  55. {
  56. Thread.Sleep (2);
  57. }
  58. int end2Tick = Environment.TickCount;
  59. Console .WriteLine ( "starttick: {0}" , end1Tick - beginTick);
  60. Console .WriteLine ( "alltick: {0}" , end2Tick - beginTick);
  61. Console .WriteLine ( "memory: {0: N0} K" , (performance_RawValue / 1024));
  62. Console .ReadLine ();
  63. }
  64. }
  65. }
* This source code was highlighted with Source Code Highlighter .


-2fiveten
-start tickall tickmemorystart tickall tickmemorystart tickall tickmemory
Single threaded-368810 792K-728110 780K-1312510 792K
Multithreaded6564234323 508K6257719323 508K75013735323 508K

When testing the performance of multithreading, a new value of the start time of processes appeared. It is this value that the total duration of the program runs. The approximate process start is 0.5 millisecond. We also see a significantly increased amount of used memory that is spent on the stack of the threads being run.
')

Results


Select all compared values ​​in the table.
-Single threadedMultithreaded
Total timeThe total time of the main thread depends on the execution time of all requests.The time of the main thread depends only on the number of requests.
Total CPU TimeLow parasitic loadsParasitic loads 2 times higher
MemoryLow memory queries, independent of the number of requestsEach request consumes at least 256KB of memory per thread stack.


Such a “student laboratory work” came out in the study of this issue. Please do not throw stones :)

Source: https://habr.com/ru/post/58931/


All Articles