mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 17:15:38 +00:00
Improved Call Performance test. It now outputs to the console / log file, and provides much better results.
This commit is contained in:
parent
fcfc35dc18
commit
6c4372edbc
|
@ -1,59 +0,0 @@
|
|||
namespace Examples.Tests
|
||||
{
|
||||
partial class S01_Call_Performance
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.glControl1 = new OpenTK.GLControl();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// glControl1
|
||||
//
|
||||
this.glControl1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
|
||||
this.glControl1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.glControl1.Location = new System.Drawing.Point(0, 0);
|
||||
this.glControl1.Name = "glControl1";
|
||||
this.glControl1.Size = new System.Drawing.Size(624, 444);
|
||||
this.glControl1.TabIndex = 0;
|
||||
//
|
||||
// S01_Call_Performance
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(624, 444);
|
||||
this.Controls.Add(this.glControl1);
|
||||
this.Name = "S01_Call_Performance";
|
||||
this.Text = "S01_Call_Performance";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private OpenTK.GLControl glControl1;
|
||||
}
|
||||
}
|
|
@ -5,118 +5,168 @@
|
|||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.OpenGL;
|
||||
using System.Threading;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Examples.Tests
|
||||
{
|
||||
public partial class S01_Call_Performance : Form /*, IExample*/
|
||||
public class S01_Call_Performance : IExample
|
||||
{
|
||||
public S01_Call_Performance()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Application.Idle += new EventHandler(Application_Idle);
|
||||
|
||||
// Force opengl functions
|
||||
GL.Viewport(0, 0, this.Width, this.Height);
|
||||
|
||||
this.ShowDialog();
|
||||
}
|
||||
|
||||
bool run = false;
|
||||
|
||||
OpenTK.GLContext context;
|
||||
const int num_calls = 1000000;
|
||||
float[] v = new float[] { 0.0f, 0.0f };
|
||||
|
||||
int i = 0;
|
||||
void dummy()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
//fixed (int* i_ptr = &i)
|
||||
{
|
||||
GCHandle h = GCHandle.Alloc(i, GCHandleType.Pinned);//.FromIntPtr((IntPtr)i_ptr);
|
||||
try
|
||||
{
|
||||
i = (int)h.AddrOfPinnedObject();
|
||||
}
|
||||
finally
|
||||
{
|
||||
h.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("opengl32.dll", EntryPoint = "glVertex2f")]
|
||||
extern static void glVertex2f_1(float a, float b);
|
||||
|
||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
||||
[DllImport("opengl32.dll", EntryPoint = "glVertex2f")]
|
||||
extern static void glVertex2f_2(float a, float b);
|
||||
|
||||
[System.Security.SuppressUnmanagedCodeSecurity()]
|
||||
[DllImport("opengl32.dll", EntryPoint = "glVertex2fv")]
|
||||
extern static void glVertex2fv(float[] v);
|
||||
|
||||
void Application_Idle(object sender, EventArgs e)
|
||||
{
|
||||
long count = 0;
|
||||
bool stop = false;
|
||||
|
||||
if (!run)
|
||||
{
|
||||
run = true;
|
||||
|
||||
GL.Clear(
|
||||
GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
|
||||
GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
||||
|
||||
//GL.Begin(GL.Enums.BeginMode.POINTS);
|
||||
|
||||
System.Threading.Timer timer = new System.Threading.Timer(
|
||||
new TimerCallback(delegate { stop = true; }), null, 5000, Timeout.Infinite);
|
||||
|
||||
while (!stop)
|
||||
{
|
||||
//GL.Vertex2(0.0f, 0.0f);
|
||||
GL.Vertex2(v);
|
||||
//GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB);
|
||||
//dummy();
|
||||
//GL.ColorPointer(2, GL.Enums.ColorPointerType.FLOAT, 0, v);
|
||||
//glVertex2f_1(0.0f, 0.0f);
|
||||
//glVertex2f_2(0.0f, 0.0f);
|
||||
//glVertex2fv(v);
|
||||
count++;
|
||||
}
|
||||
|
||||
//GL.End();
|
||||
|
||||
//glControl1.Context.SwapBuffers();
|
||||
|
||||
timer.Dispose();
|
||||
this.Hide();
|
||||
MessageBox.Show(String.Format("{0} calls/second.", count / 5.0));
|
||||
Application.Idle -= Application_Idle;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#region IExample Members
|
||||
public static int dummy_variable = 0;
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
using (Form f = new Form())
|
||||
{
|
||||
context = new OpenTK.GLContext(new OpenTK.DisplayMode(), new OpenTK.Platform.WindowInfo(f));
|
||||
context.CreateContext();
|
||||
|
||||
Trace.WriteLine(String.Format("Number of calls: {0}", num_calls));
|
||||
|
||||
Stopwatch timer = new Stopwatch();
|
||||
|
||||
#region Managed functions
|
||||
|
||||
Trace.Write("Timing empty loop: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing inline .Net functions: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
InlineFunction();
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing virtual .Net functions: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
VirtualFunction();
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
#endregion
|
||||
|
||||
#region OpenTK.OpenGL
|
||||
|
||||
Trace.Write("Timing OpenTK.OpenGL core functions: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
GL.Vertex2(0.0f, 0.0f);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing OpenTK.OpenGL core functions (array): ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
GL.Vertex2(v);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing OpenTK.OpenGL core functions (void*): ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
GL.CallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
|
||||
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing OpenTK.OpenGL extension functions: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
#endregion
|
||||
|
||||
#region DllImports
|
||||
|
||||
Trace.Write("Timing direct DllImport: ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
glVertex2f(0.0f, 0.0f);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
Trace.Write("Timing direct DllImport (array): ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
glVertex2fv(v);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
|
||||
Trace.Write("Timing direct DllImport (void*): ");
|
||||
timer.Start();
|
||||
for (int i = 0; ++i < num_calls; )
|
||||
{
|
||||
glCallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
|
||||
}
|
||||
timer.Stop();
|
||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||
timer.Reset();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
public void InlineFunction()
|
||||
{
|
||||
++dummy_variable;
|
||||
}
|
||||
|
||||
public virtual void VirtualFunction()
|
||||
{
|
||||
++dummy_variable;
|
||||
}
|
||||
|
||||
[DllImport("opengl32.dll", EntryPoint = "glVertex2f"), SuppressUnmanagedCodeSecurity]
|
||||
extern static void glVertex2f(float a, float b);
|
||||
|
||||
[DllImport("opengl32.dll", EntryPoint = "glVertex2fv"), SuppressUnmanagedCodeSecurity]
|
||||
extern static void glVertex2fv(float[] v);
|
||||
|
||||
[DllImport("opengl32.dll", EntryPoint = "glCallLists"), SuppressUnmanagedCodeSecurity]
|
||||
extern static void glCallLists(int count, GL.Enums.ListNameType type, object lists);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Reference in a new issue