For some testing I'm doing I need a C# function that takes around 10 seconds to execute. It will be called from an ASPX page, but I need the function to eat up CPU time on the server, not rendering time. A slow query into the Northwinds database would work, or some very slow calculations. Any ideas?
As a result of the long, low-temperature cooking, slow cookers help tenderize less-expensive cuts of meat. A slow cooker brings out the flavor in foods. A wide variety of foods can be cooked in a slow cooker, including one pot meals, soups, stews and casseroles. A slow cooker uses less electricity than an oven.
As for what kind of pot to use, most commenters agreed that a heavy casserole dish or Dutch oven would do the job nicely. One person particularly recommended using a cast-iron Dutch oven for its ability to evenly distribute heat and for the fact that it supposedly imparts a better flavor on the food.
Bella - 1.5-qt. "Smallest slow cooker...
Slow cookers cost around $30 to $100 to buy and can save you hundreds over purchasing fancy countertop convection toaster ovens and broilers. Slow cookers can also cut your grocery bill significantly by allowing you to buy cheaper cuts of meat and tenderizing them over low heat for a longer time.
Try to calculate nth prime number to simulate CPU intensive work -
public void Slow() { long nthPrime = FindPrimeNumber(1000); //set higher value for more time } public long FindPrimeNumber(int n) { int count=0; long a = 2; while(count<n) { long b = 2; int prime = 1;// to check if found a prime while(b * b <= a) { if(a % b == 0) { prime = 0; break; } b++; } if(prime > 0) { count++; } a++; } return (--a); }
How much time it will take will depend on the hardware configuration of the system.
So try with input as 1000 then either increase input value or decrease it.
This function will simulate CPU intensive work.
Arguably the simplest such function is this:
public void Slow() { var end = DateTime.Now + TimeSpan.FromSeconds(10); while (DateTime.Now < end) /* nothing here */ ; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With