Nerd-o-matic 002 – Prompts

Tags: ,

Nerd-o-matic 001 – GUID’s

Tags: ,

Comparison between Windows Forms and WPF – Initialization time and memory

I created some small applications to compare the initialization time between Windows Forms and WPF, running .NET 4.0. First it runs 100 times and then I get the average. Here are the results:

The mode for initialization time gave 31.25 milliseconds for Windows Forms and 234.37 ms for WPF. Here is the distribution of values:

I’m not sharing the exact values since for me the most important is the initialization time and not the precise comparison, which is variable between different systems. For that reason, I suggest testing in your own environment. Following is the result of profiling.

WPF:

Handles created: 605
Handles destroyed: 345
Handles surviving: 260

Windows Forms:

Handles created: 88
Handles destroyed: 15
Handles surviving: 73

All other values are zero or unknown.

The first application in Windows Forms has this code:

static class Program
{
	public static DateTime start;

	[STAThread]
	static void Main()
	{
		start = DateTime.Now;
		Application.EnableVisualStyles();
		Application.SetCompatibleTextRenderingDefault(false);
		Application.Run(new Form1());
	}
}

public partial class Form1 : Form
{
	public Form1()
	{ InitializeComponent(); }

	private void Form1_Shown(object sender, EventArgs e)
	{
		File.AppendAllText(@"C:\WinFormsStartTime.txt",
			DateTime.Now.Subtract(Program.start).TotalMilliseconds.ToString() + "\n");

		Process process = Process.GetCurrentProcess();
		File.AppendAllText(@"C:\WinFormsMemory.txt",
			process.PrivateMemorySize64.ToString() + "\n");

		Application.Exit();
	}
}

The second application has the following code:

public partial class App : Application
{
	public static DateTime start;

	protected override void OnStartup(StartupEventArgs e)
	{
		start = DateTime.Now;
		base.OnStartup(e);			
	}
}

public partial class MainWindow : Window
{
	public MainWindow()
	{ InitializeComponent(); }

	private void Window_ContentRendered(object sender, EventArgs e)
	{
		File.AppendAllText(@"C:\WpfStartTime.txt",
			DateTime.Now.Subtract(App.start).TotalMilliseconds.ToString() + "\n");

		Process process = Process.GetCurrentProcess();
		File.AppendAllText(@"C:\WpfMemory.txt",
			process.PrivateMemorySize64.ToString() + "\n");

		Application.Current.Shutdown();
	}
}
<Window x:Class="SimpleWpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" ContentRendered="Window_ContentRendered">
    <Grid>
    </Grid>
</Window>

Tags: , , ,

(Português) Trocando o cleardiff pelo WinMerge no ClearCase

Sorry, this entry is only available in Português.

Tags: ,

(Português) Alterando o arquivo RDP para aceitar conexão console

Sorry, this entry is only available in Português.

Tags: ,

(Português) DrawImage com transparência em GDI+

Sorry, this entry is only available in Português.

Tags: , ,

(Português) ManagementException “Not found”

Sorry, this entry is only available in Português.

Tags:

(Português) Criando um Windows Cluster com Virtual PC e iSCSI – Parte 4

Sorry, this entry is only available in Português.

Tags:

(Português) Criando um Windows Cluster com Virtual PC e iSCSI – Parte 3

Sorry, this entry is only available in Português.

Tags:

(Português) Criando um Windows Cluster com Virtual PC e iSCSI – Parte 2

Sorry, this entry is only available in Português.

Tags: