sw.Stop(); Console.WriteLine("{0}pcs, {1}ms", pans, sw.ElapsedMilliseconds); Console.ReadKey();
if (pans == 720) break; sw.Stop(); Console.WriteLine("{0}pcs, {1}ms", pans, sw.ElapsedMilliseconds); Console.ReadKey();
class Program { static void Main(string[] args) { Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 10000; i++) { Thread thread = new Thread(DoNothing); thread.Start(); } watch.Stop(); Console.WriteLine(watch.Elapsed); } static void DoNothing() { //Do Nothing } }
static Random r = new Random(); void Main() { int iterations = 2000; Stopwatch s = new Stopwatch(); s.Start(); Parallel.For(0, iterations, ReadFile); s.Stop(); Console.WriteLine("Total elapsed milliseconds was {0}.", s.ElapsedMilliseconds); Console.WriteLine("Total iterations were {0}.", iterations); Console.WriteLine("Total iterations per second was {0}.", iterations / s.Elapsed.TotalSeconds); } // Define other methods and classes here static async void ReadFile(int x) { string path = @"C:\Temp\random.txt"; int readSize = r.Next(512, 10 * 1024); using (StreamReader reader = new StreamReader(path)) { await reader.ReadAsync(new char[readSize], 0, readSize); } }
cnt += k; sw.Stop(); Console.WriteLine( "modulo cnt=" + cnt.ToString() + " " + sw.Elapsed.ToString() ); sw.Reset(); cnt += k; sw.Stop(); Console.WriteLine( "if cnt=" + cnt.ToString() + " " + sw.Elapsed.ToString() ); sw.Reset(); cnt += k; sw.Stop(); Console.WriteLine( "bit cnt=" + cnt.ToString() + " " + sw.Elapsed.ToString() );
Stopwatch stop1 = new Stopwatch(); Stopwatch stop2 = new Stopwatch(); //do test 100 000 times for (int j = 0; j < 100000; j++) { //generate fake data //object with 50 properties StringBuilder json = new StringBuilder(); json.Append('{'); for (int i = 0; i < 100; i++) { json.Append(String.Format("prop{0}:'val{0}',", i)); } json.Length = json.Length - 1; json.Append('}'); var line = json.ToString(); stop1.Start(); var serializer = new JavaScriptSerializer(); var jsonObject = serializer.DeserializeObject(line) as Dictionary<string, object>; stop1.Stop(); stop2.Start(); var caseInsensitiveDictionary = new Dictionary<string, object>(jsonObject, StringComparer.OrdinalIgnoreCase); stop2.Stop(); } Console.WriteLine(stop1.Elapsed); Console.WriteLine(stop2.Elapsed); Console.Read();
result = buffer.ConvertToLong(0, buffer.Length - 1); sw.Stop(); Console.WriteLine("Test {4}: {0} ticks, {1}ms, 1 conversion takes = {2}μs or {3}ns. GCs: {5}", sw.ElapsedTicks, sw.ElapsedMilliseconds, (((decimal) sw.ElapsedMilliseconds)/((decimal) iterations))*1000,
//Create TextView to display status of Wifi TextView wifitext = FindViewById<TextView>(Resource.Id.WifiTextView); //Configuring Wifi connection var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService); var activeConnection = connectivityManager.ActiveNetworkInfo; if (activeConnection != null && activeConnection.IsConnected) { wifitext.Text = "WIFI AVAILABLE"; string[] urladdress = new string[] { "https://www.google.com/", "https://www.yahoo.com/"}; for (int i = 0; i < urladdress.Length; i++) { string url = urladdress[i]; //Call async method Task returnedTask = Task_MethodAsync(url); } } else wifitext.Text = "WIFI UNAVAILABLE"; } public async Task Task_MethodAsync(string url) { LinearLayout ll = FindViewById<LinearLayout>(Resource.Id.linearLayout1); WebClient client = new WebClient(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Stream listurl = client.OpenRead(url); StreamReader reader = new StreamReader(listurl); stopwatch.Stop(); // listurl.Close(); var time = Convert.ToString(stopwatch.Elapsed);