using System; using System.Collections.Generic; using System.Linq; using System.Text; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; namespace GPUBenchmark { class Program { static readonly DateTime EPOCH = new DateTime(1970, 1, 1); static Random r = new Random((int) (DateTime.Now - EPOCH).TotalMilliseconds); static GameWindow w; static double lastTime; static void Main(string[] args) { w = new GameWindow(640, 480); w.RenderFrame += new EventHandler(w_RenderFrame); w.UpdateFrame += new EventHandler(w_UpdateFrame); GL.Ortho(-1, 1, -1, 1, 0.1, 1000); GL.Viewport(w.ClientRectangle); w.Run(60, 60); } static void w_UpdateFrame(object sender, FrameEventArgs e) { for (int i = 0; i < 100000; i++) { double rnd = r.NextDouble(); double hash1 = rnd.GetHashCode(); for (int ii = 0; ii < 16; ii++) hash1 = hash1.GetHashCode(); } } static void w_RenderFrame(object sender, FrameEventArgs e) { lastTime = (DateTime.Now - EPOCH).TotalMilliseconds; GL.Begin(BeginMode.Triangles); for (int i = 0; i < 100000; i++) { GL.Color3(r.NextDouble(), r.NextDouble(), r.NextDouble()); GL.Vertex3(r.NextDouble() - 0.5, r.NextDouble() - 0.5, r.NextDouble() - 0.5); GL.Vertex3(r.NextDouble() - 0.5, r.NextDouble() - 0.5, r.NextDouble() - 0.5); GL.Vertex3(r.NextDouble() - 0.5, r.NextDouble() - 0.5, r.NextDouble() - 0.5); } GL.End(); w.SwapBuffers(); double curTime = (DateTime.Now - EPOCH).TotalMilliseconds; double frameLenMS = curTime - lastTime; double fps = 1.0 / (frameLenMS / 1000.0); w.Title = string.Format("FPS: {0}", fps.ToString("###.00")); } } }