Skip to content

Instantly share code, notes, and snippets.

@DavidKarlas
Created May 28, 2013 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidKarlas/c3abb1fcb5a26fd1c5e4 to your computer and use it in GitHub Desktop.
Save DavidKarlas/c3abb1fcb5a26fd1c5e4 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
using System.Diagnostics;
using SFML.Window;
namespace shader
{
class Program
{
public static void Main(string[] args)
{
int loops = 10000000;
int smallLoop = 100000;
Transform a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
Transform b = new Transform(43, 54, 76, 1, 5, 765, 87, 54, 543);
Transform Identity = Transform.Identity;
MyTransform myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
MyTransform myB = new MyTransform(43, 54, 76, 1, 5, 765, 87, 54, 543);
MyTransform myIdentity = MyTransform.Identity;
Vector2f point = new Vector2f(34, 76);
FloatRect rect = new FloatRect(54, 765, 543, 54);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a.TransformPoint(point);
}
stopWatch.Stop();
Console.WriteLine("Transform TransformPoint:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA.TransformPoint(point);
}
stopWatch.Stop();
Console.WriteLine("MyTransform TransformPoint:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a.TransformRect(rect);
}
stopWatch.Stop();
Console.WriteLine("Transform TransformRect:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA.TransformRect(rect);
}
stopWatch.Stop();
Console.WriteLine("MyTransform TransformRect:" + stopWatch.ElapsedMilliseconds);
a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a *= Identity;
}
stopWatch.Stop();
Console.WriteLine("Transform Multiply(Identity):" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA *= myIdentity;
}
stopWatch.Stop();
Console.WriteLine("MyTransform Multiply(Identity):" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
}
a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < smallLoop; i++)
{
a *= b;
}
stopWatch.Stop();
Console.WriteLine("Transform Multiply:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < smallLoop; i++)
{
myA *= myB;
}
stopWatch.Stop();
Console.WriteLine("MyTransform Multiply:" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
}
a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a.Rotate(42);
}
stopWatch.Stop();
Console.WriteLine("Transform Rotate:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA.Rotate(42);
}
stopWatch.Stop();
Console.WriteLine("MyTransform Rotate:" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
Console.WriteLine("X:" + Math.Round(a.TransformPoint(point).X, 3) + " Y:" + Math.Round(a.TransformPoint(point).Y, 3));
Console.WriteLine("X:" + Math.Round(myA.TransformPoint(point).X, 3) + " Y:" + Math.Round(myA.TransformPoint(point).Y, 3));
}
a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a.Translate(point);
}
stopWatch.Stop();
Console.WriteLine("Transform Translate:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA.Translate(point);
}
stopWatch.Stop();
Console.WriteLine("MyTransform Translate:" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
}
a = new Transform(6, 7, 5, 5, 3, 7, 6, 2, 6);
myA = new MyTransform(6, 7, 5, 5, 3, 7, 6, 2, 6);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < smallLoop; i++)
{
a.Scale(1.01f, 1.01f);
}
stopWatch.Stop();
Console.WriteLine("Transform Scale:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < smallLoop; i++)
{
myA.Scale(1.01f, 1.01f);
}
stopWatch.Stop();
Console.WriteLine("MyTransform Scale:" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
}
a = new Transform(43, 65, 34, 76, 54, 76, 45, 76, 45);
myA = new MyTransform(43, 65, 34, 76, 54, 76, 45, 76, 45);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
a = a.GetInverse();
}
stopWatch.Stop();
Console.WriteLine("Transform Inverse:" + stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
for (int i = 0; i < loops; i++)
{
myA = myA.GetInverse();
}
stopWatch.Stop();
Console.WriteLine("MyTransform Inverse:" + stopWatch.ElapsedMilliseconds);
if (a.ToString() != myA.ToString())
{
Console.WriteLine(a);
Console.WriteLine(myA);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment