Skip to content

Instantly share code, notes, and snippets.

@urza
Created December 28, 2020 16:51
Show Gist options
  • Save urza/5ff111dab30fd0764d6e3bb858053886 to your computer and use it in GitHub Desktop.
Save urza/5ff111dab30fd0764d6e3bb858053886 to your computer and use it in GitHub Desktop.
c# microbenchmark
// needs C# 9.0 or newer (top level statements)
// will utilize 100 % CPU and print elapsed seconds when finished
// Ryzen 5900x - cca 150 seconds
// you can also use int.MaxValue / 100 for shorter run
using System;
using System.Threading.Tasks;
var d = DateTime.Now;
Parallel.For(0, int.MaxValue, _ => new Random() );
Console.WriteLine((DateTime.Now - d).TotalSeconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment