// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Diagnostics; using System.Threading; namespace E { public class Program { private const double LOAD = 0.25; public static void Main(string[] args) { DateTime startwall = DateTime.Now; double startcpu = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; int t = 100; while(true) { double x = 2; for(int i = 0; i < 1000000; i++) { x = Math.Pow(Math.Sqrt(x), 2); } DateTime currwall = DateTime.Now; double deltawall = (currwall - startwall).TotalMilliseconds; double currcpu = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; double deltacpu = currcpu - startcpu; double usage = deltacpu / deltawall; t = (int)(t * usage/LOAD + 0.5); Thread.Sleep(t); startwall = currwall; startcpu = currcpu; } } } }