olexander_dan

Untitled

Sep 23rd, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace BenchmarkLab {
  5.     class TypeTestsList : Benchmark {
  6.         public TypeTestsList(Object type) {
  7.             if (type is int) {
  8.                 typeTestsList.Add(() => {
  9.                     int a = 2, b = 2, c = 1;
  10.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  11.                 });
  12.                 typeTestsList.Add(() => {
  13.                     int a = 2, b = 2, c = 1;
  14.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  15.                 });
  16.                 typeTestsList.Add(() => {
  17.                     int a = 2, b = 2, c = 1;
  18.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  19.                 });
  20.                 typeTestsList.Add(() => {
  21.                     int a = 2, b = 2, c = 1;
  22.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  23.                 });
  24.             } else if (type is uint) {
  25.                 typeTestsList.Add(() => {
  26.                     uint a = 2, b = 2, c = 1;
  27.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  28.                 });
  29.                 typeTestsList.Add(() => {
  30.                     uint a = 2, b = 2, c = 1;
  31.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  32.                 });
  33.                 typeTestsList.Add(() => {
  34.                     uint a = 2, b = 2, c = 1;
  35.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  36.                 });
  37.                 typeTestsList.Add(() => {
  38.                     uint a = 2, b = 2, c = 1;
  39.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  40.                 });
  41.             } else if (type is long) {
  42.                 typeTestsList.Add(() => {
  43.                     long a = 2, b = 2, c = 1;
  44.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  45.                 });
  46.                 typeTestsList.Add(() => {
  47.                     long a = 2, b = 2, c = 1;
  48.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  49.                 });
  50.                 typeTestsList.Add(() => {
  51.                     long a = 2, b = 2, c = 1;
  52.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  53.                 });
  54.                 typeTestsList.Add(() => {
  55.                     long a = 2, b = 2, c = 1;
  56.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  57.                 });
  58.             } else if (type is ulong) {
  59.                 typeTestsList.Add(() => {
  60.                     ulong a = 2, b = 2, c = 1;
  61.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  62.                 });
  63.                 typeTestsList.Add(() => {
  64.                     ulong a = 2, b = 2, c = 1;
  65.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  66.                 });
  67.                 typeTestsList.Add(() => {
  68.                     ulong a = 2, b = 2, c = 1;
  69.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  70.                 });
  71.                 typeTestsList.Add(() => {
  72.                     ulong a = 2, b = 2, c = 1;
  73.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  74.                 });
  75.             } else if (type is float) {
  76.                 typeTestsList.Add(() => {
  77.                     float a = 2f, b = 2f, c = 1f;
  78.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  79.                 });
  80.                 typeTestsList.Add(() => {
  81.                     float a = 2f, b = 2f, c = 1f;
  82.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  83.                 });
  84.                 typeTestsList.Add(() => {
  85.                     float a = 2f, b = 2f, c = 1f;
  86.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  87.                 });
  88.                 typeTestsList.Add(() => {
  89.                     float a = 2f, b = 2f, c = 1f;
  90.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  91.                 });
  92.             } else if (type is double) {
  93.                 typeTestsList.Add(() => {
  94.                     double a = 2d, b = 2d, c = 1d;
  95.                     for (int i = 0; i < NumOfIterations; ++i) { a = b + c; b = a + c; c = a + b; }
  96.                 });
  97.                 typeTestsList.Add(() => {
  98.                     double a = 2d, b = 2d, c = 1d;
  99.                     for (int i = 0; i < NumOfIterations; ++i) { a = b - c; b = a - c; c = a - b; }
  100.                 });
  101.                 typeTestsList.Add(() => {
  102.                     double a = 2d, b = 2d, c = 1d;
  103.                     for (int i = 0; i < NumOfIterations; ++i) { a = b * c; b = a * c; c = a * b; }
  104.                 });
  105.                 typeTestsList.Add(() => {
  106.                     double a = 2d, b = 2d, c = 1d;
  107.                     for (int i = 0; i < NumOfIterations; ++i) { a = b / c; b = a / c; c = a / b; }
  108.                 });
  109.             } else
  110.                 throw new System.ArgumentException("Unknown type of argument!");
  111.         }
  112.         public List<Action> typeTestsList { get; private set; } = new List<Action>();
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment