Skip to content

Instantly share code, notes, and snippets.

@ZeroStride
Created April 4, 2010 22:39
Show Gist options
  • Save ZeroStride/355765 to your computer and use it in GitHub Desktop.
Save ZeroStride/355765 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
// AoS 28-bytes
// this test uses an array of particle structures 28-bytes wide and processes each particle individually
namespace XNA360MathTest
{
static class Program
{
struct ParticleStruct
{
public Vector3 pos;
public Vector3 vel;
public float timeremaining;
}
static unsafe void Main(string[] args)
{
const int NumParticles = 3200000;
const float dt = 0.04f;
const int NumSimulationRuns = 50;
ParticleStruct[] particle_stream = new ParticleStruct[NumParticles];
Random rnd = new Random();
for (int i = 0; i < NumParticles; i++)
{
particle_stream[i].pos.X = (float)rnd.NextDouble();
particle_stream[i].pos.Y = (float)rnd.NextDouble();
particle_stream[i].pos.Z = (float)rnd.NextDouble();
particle_stream[i].vel.X = (float)rnd.NextDouble();
particle_stream[i].vel.Y = (float)rnd.NextDouble();
particle_stream[i].vel.Z = (float)rnd.NextDouble();
particle_stream[i].timeremaining = (float)rnd.NextDouble();
}
Stopwatch hptimer = new Stopwatch();
float simAvg = 0.0f;
float simMin = float.PositiveInfinity;
float simMax = 0.0f;
Vector3 dpdt;
Vector3 dt_v = new Vector3(dt);
for (int j = 0; j < NumSimulationRuns; j++)
{
hptimer.Reset();
hptimer.Start();
for (int i = 0; i < NumParticles; i++)
{
Vector3.Multiply(ref particle_stream[i].vel, ref dt_v, out dpdt);
Vector3.Add(ref particle_stream[i].pos, ref dpdt, out particle_stream[i].pos);
particle_stream[i].timeremaining -= dt;
}
hptimer.Stop();
float elapsedMS = hptimer.ElapsedTicks * 1000.0f / (float)Stopwatch.Frequency;
simAvg += elapsedMS;
simMin = (simMin > elapsedMS ? elapsedMS : simMin);
simMax = (simMax < elapsedMS ? elapsedMS : simMax);
}
simAvg /= NumSimulationRuns;
string outpt = "Average: " + simAvg + " Min: " + simMin + " Max: " + simMax;
Console.WriteLine(outpt); // Set breakpoint here
}
}
}
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
// AoS 44-bytes
// this test uses an array of particle structures 44-bytes wide and processes each particle individually
namespace XNA360MathTest
{
static class Program
{
struct ParticleStruct
{
public Vector3 pos;
public Vector3 vel;
public float timeremaining;
// Represents stuff that the simulation doesn't care about, but needs to be in a pure AoS configuration
public Vector4 JunkInTheTrunk0;
}
static unsafe void Main(string[] args)
{
const int NumParticles = 1600000;
const float dt = 0.04f;
const int NumSimulationRuns = 50;
ParticleStruct[] particle_stream = new ParticleStruct[NumParticles];
Random rnd = new Random();
for (int i = 0; i < NumParticles; i++)
{
particle_stream[i].pos.X = (float)rnd.NextDouble();
particle_stream[i].pos.Y = (float)rnd.NextDouble();
particle_stream[i].pos.Z = (float)rnd.NextDouble();
particle_stream[i].vel.X = (float)rnd.NextDouble();
particle_stream[i].vel.Y = (float)rnd.NextDouble();
particle_stream[i].vel.Z = (float)rnd.NextDouble();
particle_stream[i].timeremaining = (float)rnd.NextDouble();
}
Stopwatch hptimer = new Stopwatch();
float simAvg = 0.0f;
float simMin = float.PositiveInfinity;
float simMax = 0.0f;
Vector3 dpdt;
Vector3 dt_v = new Vector3(dt);
for (int j = 0; j < NumSimulationRuns; j++)
{
hptimer.Reset();
hptimer.Start();
for (int i = 0; i < NumParticles; i++)
{
Vector3.Multiply(ref particle_stream[i].vel, ref dt_v, out dpdt);
Vector3.Add(ref particle_stream[i].pos, ref dpdt, out particle_stream[i].pos);
particle_stream[i].timeremaining -= dt;
}
hptimer.Stop();
float elapsedMS = hptimer.ElapsedTicks * 1000.0f / (float)Stopwatch.Frequency;
simAvg += elapsedMS;
simMin = (simMin > elapsedMS ? elapsedMS : simMin);
simMax = (simMax < elapsedMS ? elapsedMS : simMax);
}
simAvg /= NumSimulationRuns;
string outpt = "Average: " + simAvg + " Min: " + simMin + " Max: " + simMax;
Console.WriteLine(outpt); // Set breakpoint here
}
}
}
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
// AoS 56-bytes
// this test uses an array of particle structures 56-bytes wide and processes each particle individually
namespace XNA360MathTest
{
static class Program
{
struct ParticleStruct
{
public Vector3 pos;
public Vector3 vel;
public float timeremaining;
// Represents stuff that the simulation doesn't care about, but needs to be in a pure AoS configuration
public Vector4 JunkInTheTrunk0;
public Vector3 JunkInTheTrunk1;
}
static unsafe void Main(string[] args)
{
const int NumParticles = 1600000;
const float dt = 0.04f;
const int NumSimulationRuns = 50;
ParticleStruct[] particle_stream = new ParticleStruct[NumParticles];
Random rnd = new Random();
for (int i = 0; i < NumParticles; i++)
{
particle_stream[i].pos.X = (float)rnd.NextDouble();
particle_stream[i].pos.Y = (float)rnd.NextDouble();
particle_stream[i].pos.Z = (float)rnd.NextDouble();
particle_stream[i].vel.X = (float)rnd.NextDouble();
particle_stream[i].vel.Y = (float)rnd.NextDouble();
particle_stream[i].vel.Z = (float)rnd.NextDouble();
particle_stream[i].timeremaining = (float)rnd.NextDouble();
}
Stopwatch hptimer = new Stopwatch();
float simAvg = 0.0f;
float simMin = float.PositiveInfinity;
float simMax = 0.0f;
Vector3 dpdt;
Vector3 dt_v = new Vector3(dt);
for (int j = 0; j < NumSimulationRuns; j++)
{
hptimer.Reset();
hptimer.Start();
for (int i = 0; i < NumParticles; i++)
{
Vector3.Multiply(ref particle_stream[i].vel, ref dt_v, out dpdt);
Vector3.Add(ref particle_stream[i].pos, ref dpdt, out particle_stream[i].pos);
particle_stream[i].timeremaining -= dt;
}
hptimer.Stop();
float elapsedMS = hptimer.ElapsedTicks * 1000.0f / (float)Stopwatch.Frequency;
simAvg += elapsedMS;
simMin = (simMin > elapsedMS ? elapsedMS : simMin);
simMax = (simMax < elapsedMS ? elapsedMS : simMax);
}
simAvg /= NumSimulationRuns;
string outpt = "Average: " + simAvg + " Min: " + simMin + " Max: " + simMax;
Console.WriteLine(outpt); // Set breakpoint here
}
}
}
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
// AoS 64-bytes
// this test uses an array of particle structures 64-bytes wide and processes each particle individually
namespace XNA360MathTest
{
static class Program
{
struct ParticleStruct
{
public Vector3 pos;
public Vector3 vel;
public float timeremaining;
// Represents stuff that the simulation doesn't care about, but needs to be in a pure AoS configuration
public Vector4 JunkInTheTrunk0;
public Vector3 JunkInTheTrunk1;
public Vector2 JunkInTheTrunk2;
}
static unsafe void Main(string[] args)
{
const int NumParticles = 1600000;
const float dt = 0.04f;
const int NumSimulationRuns = 50;
ParticleStruct[] particle_stream = new ParticleStruct[NumParticles];
Random rnd = new Random();
for (int i = 0; i < NumParticles; i++)
{
particle_stream[i].pos.X = (float)rnd.NextDouble();
particle_stream[i].pos.Y = (float)rnd.NextDouble();
particle_stream[i].pos.Z = (float)rnd.NextDouble();
particle_stream[i].vel.X = (float)rnd.NextDouble();
particle_stream[i].vel.Y = (float)rnd.NextDouble();
particle_stream[i].vel.Z = (float)rnd.NextDouble();
particle_stream[i].timeremaining = (float)rnd.NextDouble();
}
Stopwatch hptimer = new Stopwatch();
float simAvg = 0.0f;
float simMin = float.PositiveInfinity;
float simMax = 0.0f;
Vector3 dpdt;
Vector3 dt_v = new Vector3(dt);
for (int j = 0; j < NumSimulationRuns; j++)
{
hptimer.Reset();
hptimer.Start();
for (int i = 0; i < NumParticles; i++)
{
Vector3.Multiply(ref particle_stream[i].vel, ref dt_v, out dpdt);
Vector3.Add(ref particle_stream[i].pos, ref dpdt, out particle_stream[i].pos);
particle_stream[i].timeremaining -= dt;
}
hptimer.Stop();
float elapsedMS = hptimer.ElapsedTicks * 1000.0f / (float)Stopwatch.Frequency;
simAvg += elapsedMS;
simMin = (simMin > elapsedMS ? elapsedMS : simMin);
simMax = (simMax < elapsedMS ? elapsedMS : simMax);
}
simAvg /= NumSimulationRuns;
string outpt = "Average: " + simAvg + " Min: " + simMin + " Max: " + simMax;
Console.WriteLine(outpt); // Set breakpoint here
}
}
}
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
// AoS 72-bytes
// this test uses an array of particle structures 72-bytes wide and processes each particle individually
namespace XNA360MathTest
{
static class Program
{
struct ParticleStruct
{
public Vector3 pos;
public Vector3 vel;
public float timeremaining;
// Represents stuff that the simulation doesn't care about, but needs to be in a pure AoS configuration
public Vector4 JunkInTheTrunk0;
public Vector3 JunkInTheTrunk1;
public Vector2 JunkInTheTrunk2;
public Vector2 JunkInTheTrunk3;
}
static unsafe void Main(string[] args)
{
const int NumParticles = 1600000;
const float dt = 0.04f;
const int NumSimulationRuns = 50;
ParticleStruct[] particle_stream = new ParticleStruct[NumParticles];
Random rnd = new Random();
for (int i = 0; i < NumParticles; i++)
{
particle_stream[i].pos.X = (float)rnd.NextDouble();
particle_stream[i].pos.Y = (float)rnd.NextDouble();
particle_stream[i].pos.Z = (float)rnd.NextDouble();
particle_stream[i].vel.X = (float)rnd.NextDouble();
particle_stream[i].vel.Y = (float)rnd.NextDouble();
particle_stream[i].vel.Z = (float)rnd.NextDouble();
particle_stream[i].timeremaining = (float)rnd.NextDouble();
}
Stopwatch hptimer = new Stopwatch();
float simAvg = 0.0f;
float simMin = float.PositiveInfinity;
float simMax = 0.0f;
Vector3 dpdt;
Vector3 dt_v = new Vector3(dt);
for (int j = 0; j < NumSimulationRuns; j++)
{
hptimer.Reset();
hptimer.Start();
for (int i = 0; i < NumParticles; i++)
{
Vector3.Multiply(ref particle_stream[i].vel, ref dt_v, out dpdt);
Vector3.Add(ref particle_stream[i].pos, ref dpdt, out particle_stream[i].pos);
particle_stream[i].timeremaining -= dt;
}
hptimer.Stop();
float elapsedMS = hptimer.ElapsedTicks * 1000.0f / (float)Stopwatch.Frequency;
simAvg += elapsedMS;
simMin = (simMin > elapsedMS ? elapsedMS : simMin);
simMax = (simMax < elapsedMS ? elapsedMS : simMax);
}
simAvg /= NumSimulationRuns;
string outpt = "Average: " + simAvg + " Min: " + simMin + " Max: " + simMax;
Console.WriteLine(outpt); // Set breakpoint here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment