T-D-K

Untitled

Dec 24th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2 {
  4.     public class Benchmark {
  5.         int simpleField;
  6.  
  7.         public int AutoProperty { get; set; }
  8.         public int SimpleProperty { get { return simpleField; } set { simpleField = value; } }
  9.         public int ComplexProperty { get { return SimpleProperty + 20; } }
  10.  
  11.         public void GlobalSetup() {
  12.             AutoProperty = 100;
  13.         }
  14.  
  15.         public void ForSupressJit() {
  16.             simpleField += 10;
  17.         }
  18.  
  19.         public int ForToAutoProperty() {
  20.             int sum = 0;
  21.             for (int i = 0; i < AutoProperty; i++) {
  22.                 sum += i;
  23.             }
  24.             return sum;
  25.         }
  26.  
  27.         public int ForToSimpleProperty() {
  28.             int sum = 0;
  29.             for(int i = 0; i < SimpleProperty; i++) {
  30.                 sum += i;
  31.             }
  32.             return sum;
  33.         }
  34.  
  35.         public int ForToComplexProperty() {
  36.             int sum = 0;
  37.             for(int i = 0; i < ComplexProperty; i++) {
  38.                 sum += i;
  39.             }
  40.             return sum;
  41.         }
  42.  
  43.     }
  44.  
  45.     class Program {
  46.         static void Main(string[] args) {
  47.             Benchmark b = new Benchmark();
  48.             b.GlobalSetup();
  49.             b.ForToAutoProperty();
  50.             b.ForToComplexProperty();
  51.             b.ForToSimpleProperty();
  52.             Console.ReadLine();
  53.             b.ForToAutoProperty();
  54.             b.ForToComplexProperty();
  55.             b.ForToSimpleProperty();
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment