Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 28 February 2008 - 09:38 PM
Posted 29 February 2008 - 07:25 AM
Posted 02 March 2008 - 02:58 AM
Posted 02 March 2008 - 03:07 AM
Posted 02 March 2008 - 03:25 AM
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
Posted 02 March 2008 - 07:29 AM
unsafe
{
__asm
{
}
}
Posted 02 March 2008 - 11:32 AM
Posted 02 March 2008 - 07:02 PM
Posted 02 March 2008 - 10:21 PM
Testing 30.000.000 iterations.
OpenTK Add Func - 00:00:00.3910775
OpenTK Add Op - 00:00:01.3609497
Sharp3 Add Func - 00:00:01.0324446
Sharp3 Add Op - 00:00:01.6581686
Potter Add - 00:00:01.6894548
OpenTK Sub Func - 00:00:00.3754344
OpenTK Sub Op - 00:00:01.3609497
Sharp3 Sub Func - 00:00:01.0480877
Sharp3 Sub Op - 00:00:01.6738117
Potter Sub - 00:00:01.6581686
OpenTK Mul Scalar Func - 00:00:00.3597913
OpenTK Mul Scalar Op - 00:00:01.2983773
Sharp3 Mul Scalar Func - 00:00:01.0637308
Sharp3 Mul Scalar Op - 00:00:01.7676703
Potter Mul Scalar - 00:00:01.5643100
OpenTK Div Scalar Func - 00:00:00.5005792
OpenTK Div Scalar Op - 00:00:01.2670911
Sharp3 Div Scalar Func - 00:00:01.7676703
Sharp3 Div Scalar Op - 00:00:02.3621081
Potter Div Scalar - 00:00:02.3777512
OpenTK Dot - 00:00:00.9855153
Sharp3 Dot - 00:00:01.0011584
Potter Dot - 00:00:01.2201618
OpenTK Cross Copy - 00:00:01.5799531
OpenTK Cross Ref - 00:00:00.4380068
Sharp3 Cross - 00:00:01.7363841
Potter Cross - 00:00:01.8615289
OpenTK Length - 00:00:00.7821550
Sharp3 Length - 00:00:00.7821550
Potter Length - 00:00:04.2082447
OpenTK Length Squared - 00:00:00.3754632
Sharp3 Length Squared - 00:00:00.3598189
OpenTK Normalize - 00:00:02.0024704
Sharp3 Normalize - 00:00:02.7533968
Potter Normalize - 00:00:10.3252380
OpenTK Normalize Fast - 00:00:02.1589134
using System;
using System.Collections.Generic;
using System.Text;
namespace PerfTest_Vector3
{
class Program
{
private delegate void TestDel();
static void Main(string[] args)
{
// Init.
Random rand = new Random();
float scalar = (float)rand.NextDouble();
float x1 = (float)rand.NextDouble();
float y1 = (float)rand.NextDouble();
float z1 = (float)rand.NextDouble();
float x2 = (float)rand.NextDouble();
float y2 = (float)rand.NextDouble();
float z2 = (float)rand.NextDouble();
OpenTK.Math.Vector3 tk1 = new OpenTK.Math.Vector3(x1, y1, z1);
OpenTK.Math.Vector3 tk2 = new OpenTK.Math.Vector3(x2, y2, z2);
OpenTK.Math.Vector3 tk3 = new OpenTK.Math.Vector3();
Sharp3D.Math.Core.Vector3F sh1 = new Sharp3D.Math.Core.Vector3F(x1, y1, z1);
Sharp3D.Math.Core.Vector3F sh2 = new Sharp3D.Math.Core.Vector3F(x2, y2, z2);
Sharp3D.Math.Core.Vector3F sh3 = new Sharp3D.Math.Core.Vector3F();
Vector3F rp1 = new Vector3F(x1, y1, z1);
Vector3F rp2 = new Vector3F(x2, y2, z2);
Vector3F rp3 = new Vector3F();
const int iters = 30000000;
// Test
Console.WriteLine("Testing {0:n} iterations.", iters);
Console.WriteLine();
// Test Add
Test("OpenTK Add Func ", iters, delegate() { OpenTK.Math.Vector3.Add(ref tk1, ref tk2, out tk3); });
Test("OpenTK Add Op ", iters, delegate() { tk3 = tk1 + tk2; });
Test("Sharp3 Add Func ", iters, delegate() { Sharp3D.Math.Core.Vector3F.Add(sh1, sh2, ref sh3); });
Test("Sharp3 Add Op ", iters, delegate() { sh3 = sh1 + sh2; });
Test("Potter Add ", iters, delegate() { rp3 = rp1 + rp2; });
Console.WriteLine();
// Test Sub
Test("OpenTK Sub Func ", iters, delegate() { OpenTK.Math.Vector3.Sub(ref tk1, ref tk2, out tk3); });
Test("OpenTK Sub Op ", iters, delegate() { tk3 = tk1 - tk2; });
Test("Sharp3 Sub Func ", iters, delegate() { Sharp3D.Math.Core.Vector3F.Subtract(sh1, sh2, ref sh3); });
Test("Sharp3 Sub Op ", iters, delegate() { sh3 = sh1 - sh2; });
Test("Potter Sub ", iters, delegate() { rp3 = rp1 - rp2; });
Console.WriteLine();
// Test Mul Scalar
Test("OpenTK Mul Scalar Func ", iters, delegate() { OpenTK.Math.Vector3.Mult(ref tk1, scalar, out tk3); });
Test("OpenTK Mul Scalar Op ", iters, delegate() { tk3 = tk1 * scalar; });
Test("Sharp3 Mul Scalar Func ", iters, delegate() { Sharp3D.Math.Core.Vector3F.Multiply(sh1, scalar, ref sh3); });
Test("Sharp3 Mul Scalar Op ", iters, delegate() { sh3 = sh1 * scalar; });
Test("Potter Mul Scalar ", iters, delegate() { rp3 = rp1 * scalar; });
Console.WriteLine();
// Test Div Scalar
Test("OpenTK Div Scalar Func ", iters, delegate() { OpenTK.Math.Vector3.Div(ref tk1, scalar, out tk3); });
Test("OpenTK Div Scalar Op ", iters, delegate() { tk3 = tk1 / scalar; });
Test("Sharp3 Div Scalar Func ", iters, delegate() { Sharp3D.Math.Core.Vector3F.Divide(sh1, scalar, ref sh3); });
Test("Sharp3 Div Scalar Op ", iters, delegate() { sh3 = sh1 / scalar; });
Test("Potter Div Scalar ", iters, delegate() { rp3 = rp1 / scalar; });
Console.WriteLine();
// Test Dot
Test("OpenTK Dot ", iters, delegate() { scalar = OpenTK.Math.Vector3.Dot(tk1, tk2); });
Test("Sharp3 Dot ", iters, delegate() { scalar = Sharp3D.Math.Core.Vector3F.DotProduct(sh1, sh2); });
Test("Potter Dot ", iters, delegate() { scalar = rp1.DotProduct(rp2); });
Console.WriteLine();
// Test Cross
Test("OpenTK Cross Copy ", iters, delegate() { tk3 = OpenTK.Math.Vector3.Cross(tk1, tk2); });
Test("OpenTK Cross Ref ", iters, delegate() { OpenTK.Math.Vector3.Cross(ref tk1, ref tk2, out tk3); });
Test("Sharp3 Cross ", iters, delegate() { sh3 = Sharp3D.Math.Core.Vector3F.CrossProduct(sh1, sh2); });
Test("Potter Cross ", iters, delegate() { rp3 = rp1.CrossProduct(rp2); });
Console.WriteLine();
// Test Length
Test("OpenTK Length ", iters, delegate() { scalar = tk1.Length; });
Test("Sharp3 Length ", iters, delegate() { scalar = sh1.GetLength(); });
Test("Potter Length ", iters, delegate() { scalar = rp1.Magnitude; });
Console.WriteLine();
// Test Length Squared
Test("OpenTK Length Squared ", iters, delegate() { scalar = tk1.LengthSquared; });
Test("Sharp3 Length Squared ", iters, delegate() { scalar = sh1.GetLengthSquared(); });
Console.WriteLine();
// Test Normalize
Test("OpenTK Normalize ", iters, delegate() { tk1.Normalize(); });
Test("Sharp3 Normalize ", iters, delegate() { sh1.Normalize(); });
Test("Potter Normalize ", iters, delegate() { rp1.Normalize(); });
Console.WriteLine();
// Test Normalize Fast
Test("OpenTK Normalize Fast ", iters, delegate() { tk1.NormalizeFast(); });
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Finished");
Console.ReadLine();
}
private static void Test(string prefix, int iters, TestDel testFunc)
{
DateTime start = DateTime.Now;
for (int i = 0; i < iters; i++)
{
testFunc();
}
TimeSpan span = DateTime.Now - start;
Console.WriteLine("{0} - {1}", prefix, span);
}
}
}
Posted 02 March 2008 - 10:37 PM
Quote:
Original post by cignox1
Another possible problem I see with a generic class is that unless you specialize pretty much all basic methods, you will end up with a lot of loops "for (int i = 0; i < vector_size; i++) ..." wich are not a really good thing for performance. I don't know how much smart is the compiler, nor generics have some features to avoid this, but if you must specialize the operations then you loose the gain of a generic vector anyway...
Posted 03 March 2008 - 12:59 AM
Quote:
Original post by Ezbez Quote:
Original post by cignox1
Another possible problem I see with a generic class is that unless you specialize pretty much all basic methods, you will end up with a lot of loops "for (int i = 0; i < vector_size; i++) ..." wich are not a really good thing for performance. I don't know how much smart is the compiler, nor generics have some features to avoid this, but if you must specialize the operations then you loose the gain of a generic vector anyway...
Oops! I think you're thinking of the wrong type of vector! There's the math "vector" that the OP is looking for which is a direction and a speed/distance. And there's also the container that you're talking about. Easy mistake to make.
Quote:
Original post by Ezbez
The problem with a VectorN abstract base class is that the operators would take VectorNs as parameters. However, a Vector3 cannot be added to a Vector2. The same goes for most operations. This means that you'd really want one operator to take two Vector3s and another to take two Vector2s, but none to take one Vector3 and one Vector2. However, all you'd have is ones that take both VectorNs which could be given one of each vector type.
Posted 03 March 2008 - 07:25 PM
Quote:
Original post by Julian90 Quote:
Original post by Ezbez Quote:
Original post by cignox1
Another possible problem I see with a generic class is that unless you specialize pretty much all basic methods, you will end up with a lot of loops "for (int i = 0; i < vector_size; i++) ..."
Oops! I think you're thinking of the wrong type of vector! There's the math "vector" that the OP is looking for which is a direction and a speed/distance. And there's also the container that you're talking about. Easy mistake to make.
No, I think he was thinking a maths vector, someone mentioned a VectorN class from which a Vector2 and Vector3 would derive and he was referring to the need to loop in implementing (for example) addition in a VectorN class.
Posted 03 March 2008 - 07:50 PM
Quote:
cignox1
Yes, that's what I was refering to.
Quote:
Original post by teichgraf
The nicest would be if I have a VectorN class with all operators and Vector3 / Vector2 which are derived from VectorN. So i don't have to implement the operators twice. But I think this is also slow because of the virtual calls and for-loops in the operators.
Quote:
Original post by Fiddler
OpenTK also comes with a fairly full-featured math library (Vectors, Matrices, Quaternions).As a bonus, it contains both single precision and double precision structs, which will come in handy in the future when video cards will support 64bit precision.
Posted 11 March 2008 - 10:26 PM
Quote:
I did not found double and float structs. There are only float structs in the current implementation.
And how can one write generics in .Net 2.0 for double and float. Such as Vector3<float> ... ?
Thanks in advance.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.