Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- namespace GenericsSpeedTest
- {
- static class Program
- {
- static int BiggerInt(int i, int j)
- {
- return (i.CompareTo(j) > 0) ? i : j;
- }
- static T Bigger<T>(T i, T j) where T : IComparable<T>
- {
- return (i.CompareTo(j) > 0) ? i : j;
- }
- static int _count = 10000;
- static void NonJeneric()
- {
- for (int j = 0; j < _count; ++j)
- {
- for (int i = 0; i < _count; ++i)
- {
- var tmp = BiggerInt(i, j);
- }
- }
- }
- static void GenericsInt()
- {
- for (int j = 0; j < _count; ++j)
- {
- for (int i = 0; i < _count; ++i)
- {
- var tmp = Bigger(i, j);
- }
- }
- }
- static void Main(string[] args)
- {
- var sw = new Stopwatch();
- sw.Restart();
- GenericsInt();
- sw.Stop();
- Console.WriteLine(sw.ElapsedMilliseconds);
- sw.Restart();
- GenericsInt();
- sw.Stop();
- Console.WriteLine(sw.ElapsedMilliseconds);
- sw.Restart();
- NonJeneric();
- sw.Stop();
- Console.WriteLine(sw.ElapsedMilliseconds);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement