Skip to content

Instantly share code, notes, and snippets.

@oscyp
Last active September 21, 2021 16:48
Show Gist options
  • Save oscyp/06faa380fe148c388ed81fd4db96d886 to your computer and use it in GitHub Desktop.
Save oscyp/06faa380fe148c388ed81fd4db96d886 to your computer and use it in GitHub Desktop.
Stopwatch snippets for Visual Studio. By inplace insert or surround. 3 versions: pure (sw), with console (swc) or debug (swd) output. C# and VB supported.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Stopwatch</Title>
<Author>oscyp</Author>
<Description>Insert or surround by stopwatch snippet</Description>
<Shortcut>sw</Shortcut>
<SnippetTypes>
<SnippetType>SurroundsWith/Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Runtime.Extensions.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
</Imports>
<Code Language="CSharp">
<![CDATA[var sw = new Stopwatch();
sw.Start();
$selected$
sw.Stop();$end$]]>
</Code>
<Code Language="VB">
<![CDATA[Dim sw As Stopwatch = Stopwatch.StartNew()
sw.Start()
$selected$
sw.Stop()$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Stopwatch Console</Title>
<Author>oscyp</Author>
<Description>Insert or surround by stopwatch snippet with console output</Description>
<Shortcut>swc</Shortcut>
<SnippetTypes>
<SnippetType>SurroundsWith/Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Runtime.Extensions.dll</Assembly>
<Assembly>System.Console.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Code Language="CSharp">
<![CDATA[var sw = Stopwatch.StartNew();
$selected$
sw.Stop();
Console.WriteLine(sw.Elapsed);$end$]]>
</Code>
<Code Language="VB">
<![CDATA[Dim sw As Stopwatch = Stopwatch.StartNew()
$selected$
sw.Stop()
Console.WriteLine(sw.Elapsed)$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Stopwatch Debug</Title>
<Author>oscyp</Author>
<Description>Insert or surround by stopwatch snippet with debug output</Description>
<Shortcut>swd</Shortcut>
<SnippetTypes>
<SnippetType>SurroundsWith/Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Runtime.Extensions.dll</Assembly>
<Assembly>System.Console.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Diagnostics</Namespace>
</Import>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Code Language="CSharp">
<![CDATA[var sw = Stopwatch.StartNew();
$selected$
sw.Stop();
Debug.WriteLine(sw.Elapsed);$end$]]>
</Code>
<Code Language="VB">
<![CDATA[Dim sw As Stopwatch = Stopwatch.StartNew()
$selected$
sw.Stop()
Debug.WriteLine(sw.Elapsed)$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment