private static void Main(string[] args) { //List<int> A = new List<int>(); //List<int> B = new List<int>(); //Random rand = new Random(); //for (int i = 0; i < 40000; i++) //{ // A.Add(rand.Next(400000000)); // B.Add(rand.Next(400000000)); //} //A.Sort(); //B.Sort(); int[] perm = new int[100000]; for (var a = 1; a < 100001; a++) { perm[a - 1] = a; } TimeComplexity tc = new TimeComplexity(); Stopwatch timer = new Stopwatch(); timer.Start(); //var test = solution(400000000, 400000000, 3, A.ToArray(), B.ToArray()); //var test = solution2(new[] {3, 1, 2, 4, 3}); //var test = FrogJmp(10, 1000000000, 30); var test = tc.ElementMissing(perm); timer.Start(); Console.WriteLine(test); Console.WriteLine(timer.Elapsed); }
/// <summary> /// Verify if the user credentials are valid /// </summary> /// <param name="username">MAL Username</param> /// <param name="password">MAL Password</param> /// <returns></returns> public async Task<HttpResponseMessage> Get([FromUri] string username, [FromUri] string password) { var stopWatch = new Stopwatch(); stopWatch.Start(); Log.Information("Received credential verification request for {username}", username); bool result; try { result = await _credentialVerification.VerifyCredentials(username, password); } catch (UnauthorizedAccessException) { Log.Information("Received unauthorized - Credentials for {username} isn't valid", username); result = false; } catch (Exception ex) { Log.Error(ex, "An error occured while trying to validate user credentails"); result = false; } var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent($"Valid Credetials: {result}"); stopWatch.Start(); Log.Information("Verification completed for {username}. Processing took {duration}", username, stopWatch.Elapsed); return response; }
public static void Main() { Stopwatch watch = new Stopwatch(); Random rand = new Random(); watch.Start(); for (int i = 0; i < iterations; i++) DayOfYear1(rand.Next(1, 13), rand.Next(1, 29)); watch.Stop(); Console.WriteLine("Local array: " + watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < iterations; i++) DayOfYear2(rand.Next(1, 13), rand.Next(1, 29)); watch.Stop(); Console.WriteLine("Static array: " + watch.Elapsed); // trying to modify static int [] daysCumulativeDays[0] = 18; foreach (int days in daysCumulativeDays) { Console.Write("{0}, ", days); } Console.WriteLine(""); // MY_STR_CONST = "NOT CONST"; }
private void btnInterpretate_Click(object sender, EventArgs e) { try { Stopwatch timer = new Stopwatch(); RegularExpression r; timer.Reset(); timer.Start(); r = new RegularExpression(txtRegEx.Text); timer.Stop(); ReportResult("Parsing '" + txtRegEx.Text + "'", "SUCCESS", r.IsCompiled, timer); timer.Reset(); timer.Start(); bool result = r.IsMatch(txtInput.Text); timer.Stop(); ReportResult("Matching '" + txtInput.Text + "'", result.ToString(), r.IsCompiled, timer); ReportData("Original Expression:\t" + r.OriginalExpression + "\r\nInfix Expression:\t" + r.FormattedExpression + "\r\nPostfix string:\t" + r.PostfixExpression + "\r\n\r\nNon Deterministic Automata has\t\t" + r.NDStateCount + " states.\r\nDeterministic Automata has\t\t" + r.DStateCount + " states.\r\nOptimized Deterministic Automata has\t" + r.OptimizedDStateCount + " states."); automataViewer1.Initialize(r); } catch (RegularExpressionParser.RegularExpressionParserException exc) { ReportError("PARSER ERROR", exc.ToString()); } catch (Exception exc) { ReportError("EXCEPTION", exc.ToString()); } }
private void Form1_Load(object sender, EventArgs e) { asdassd.Add("MenuGetir", () => new MyClass()); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000000; i++) { MyClass c = new MyClass(); } sw.Stop(); MessageBox.Show(sw.ElapsedMilliseconds.ToString()); sw.Reset(); Type t = typeof(MyClass); sw.Start(); for (int i = 0; i < 1000000; i++) { var c = System.Activator.CreateInstance(Type.GetType(t.FullName)); } sw.Stop(); MessageBox.Show(sw.ElapsedMilliseconds.ToString()); sw.Reset(); sw.Start(); for (int i = 0; i < 1000000; i++) { var c = asdassd["MenuGetir"](); } sw.Stop(); MessageBox.Show(sw.ElapsedMilliseconds.ToString()); }
internal static void Main() { var stopwatch = new Stopwatch(); var context = new TelerikAcademyEntities(); stopwatch.Start(); var employees = context.Employees; foreach (var employee in employees) { Console.WriteLine( "{0}, {1}, {2}", (employee.FirstName + ' ' + employee.LastName).PadLeft(30), employee.Department.Name.PadLeft(30), employee.Address.Town.Name.PadLeft(15)); } stopwatch.Stop(); Console.WriteLine("Time elapsed: {0} seconds", (decimal)stopwatch.Elapsed.Milliseconds / 1000); stopwatch.Reset(); stopwatch.Start(); var includeEmployees = context.Employees.Include("Address").Include("Department"); foreach (var employee in includeEmployees) { Console.WriteLine( "{0}, {1}, {2}", (employee.FirstName + ' ' + employee.LastName).PadLeft(30), employee.Department.Name.PadLeft(30), employee.Address.Town.Name.PadLeft(15)); } stopwatch.Stop(); Console.WriteLine("Time elapsed: {0} seconds", (decimal)stopwatch.Elapsed.Milliseconds / 1000); }
// runs an iterative deepening minimax search limited by the given timeLimit public Move IterativeDeepening(State state, double timeLimit) { int depth = 1; Stopwatch timer = new Stopwatch(); Move bestMove = null; // start the search timer.Start(); while (true) { if (timer.ElapsedMilliseconds > timeLimit) { if (bestMove == null) // workaround to overcome problem with timer running out too fast with low limits { timeLimit += 10; timer.Reset(); timer.Start(); } else { return bestMove; } } Tuple<Move, Boolean> result = IterativeDeepeningAlphaBeta(state, depth, Double.MinValue, Double.MaxValue, timeLimit, timer); if (result.Item2) bestMove = result.Item1; // only update bestMove if full recursion depth++; } }
//Double operations public static TimeSpan MesureDoubleOperationsPerformance(double num, string operation, Stopwatch stopwatch) { stopwatch.Reset(); switch (operation) { case "square root": { stopwatch.Start(); Math.Sqrt(num); stopwatch.Stop(); return stopwatch.Elapsed; } case "natural logarithm": { stopwatch.Start(); Math.Log(num); stopwatch.Stop(); return stopwatch.Elapsed; } case "sinus": { stopwatch.Start(); Math.Sin(num); stopwatch.Stop(); return stopwatch.Elapsed; } default: throw new ArgumentException("Invalid operations"); } }
static void Main(string[] args) { Stopwatch sw1 = new Stopwatch(); sw1.Start(); using (var db = new DB.MSSQL.courseMSSQLEntities()) { foreach (var i in db.Courses) { Console.WriteLine(i.NAME); } } sw1.Stop(); Console.WriteLine("Using {0} miniseconds.", sw1.ElapsedMilliseconds); sw1.Reset(); sw1.Start(); using (var db = new DB.MySQL.courseMySQLEntities()) { foreach (var i in db.courses) { Console.WriteLine(i.NAME); } } sw1.Stop(); Console.WriteLine("Using {0} miniseconds.", sw1.ElapsedMilliseconds); }
/// <summary> /// Checks if there were any changes in document types defined in Umbraco/uSiteBuilder/Both. /// Does not check relations between document types (allowed childs and allowable parents) /// </summary> /// <param name="hasDefaultValues"></param> /// <returns></returns> public static List<ContentComparison> PreviewDocumentTypeChanges(out bool hasDefaultValues) { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif // compare the library based definitions to the Umbraco DB var definedDocTypes = PreviewDocTypes(typeof(DocumentTypeBase), ""); #if DEBUG timer.Stop(); StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.PreviewDocumentTypeChanges' - only PreviewDocTypes: {0}ms.", timer.ElapsedMilliseconds)); timer.Restart(); #endif #if DEBUG timer.Start(); #endif hasDefaultValues = _hasDefaultValues; // add any umbraco defined doc types that don't exist in the class definitions definedDocTypes.AddRange(ContentTypeService.GetAllContentTypes() .Where(doctype => definedDocTypes.All(dd => dd.Alias != doctype.Alias)) .Select(docType => new ContentComparison { Alias = docType.Alias, DocumentTypeStatus = Status.Deleted, DocumentTypeId = docType.Id })); #if DEBUG timer.Stop(); StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.PreviewDocumentTypeChanges' - add any umbraco defined doc types that don't exist in the class definitions: {0}ms.", timer.ElapsedMilliseconds)); timer.Restart(); #endif return definedDocTypes; }
static void Main(string[] args) { InputLoader loader = new InputLoader(); loader.LoadFile("digits.csv"); Stopwatch sw = new Stopwatch(); var heursiticDetection = new HeuristicDetection(10, 5, quantity:50, numberOfPoints:500); var hypothesis = new CurrentHypothesis(); foreach (var input in loader.AllElements()) { ///For every new input we extract n points of interest ///And create a feature vector which characterizes the spatial relationship between these features ///For every heuristic we get a dictionary of points of interest DetectedPoints v = heursiticDetection.getFeatureVector(input.Item1); ///Compare this feature vector agaist each of the other feature vectors we know about sw.Reset(); sw.Start(); TestResult r = hypothesis.Predict(v); Debug.Print("Prediction: " + sw.Elapsed.Milliseconds.ToString()); var best= r.BestResult(); if(best != null && best.Item2 != 0){ LogProgress(best.Item1, input.Item2); } sw.Reset(); sw.Start(); hypothesis.Train(v, input.Item2, r); Debug.Print("Training: " + sw.Elapsed.Milliseconds.ToString()); //heursiticDetection.pointsOfInterest.Add(HeuristicDetection.Generate(10, 5, 10)); } }
//Problem 72 //Consider the fraction, n/d, where n and d are positive integers. //If n<d and HCF(n,d)=1, it is called a reduced proper fraction. //If we list the set of reduced proper fractions for // d ≤ 8 in ascending order of size, we get: //1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, //5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8 //It can be seen that there are 21 elements in this set. //How many elements would be contained in the set of reduced proper //fractions for d ≤ 1,000,000? //303963552391 //End of Main (21:34:38.7624901) 4/1/2008 3:03:29 PM public static void Solve(int maxD) { Console.WriteLine("Solving For {0}", maxD); Stopwatch sw = new Stopwatch(); sw.Start(); decimal cnt = 0; for (int d = maxD; d>1; d--) { int step = (d%2 == 0) ? 2 : 1; for (int n = 1; n < d; n += step) { if (Divisors.GreatestCommonDivisor(n, d) == 1) { cnt++; } } if (d % (1+(maxD / 10000)) == 0) { Console.WriteLine("{0,8} {1} {2}", d, sw.Elapsed, cnt); sw.Reset(); sw.Start(); } } Console.WriteLine(); Console.WriteLine(cnt); }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService); MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text); var sw = new Stopwatch(); sw.Start(); MgdMap map = new MgdMap(mdfId); sw.Stop(); Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds); map.SetViewScale(Convert.ToDouble(txtScale.Text)); sw.Reset(); sw.Start(); MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text)); sw.Stop(); Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds); new ImageResponseDialog(response).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } }
public void Do() { Console.WriteLine("the linklist:"); Stopwatch watch = new Stopwatch(); watch.Start(); { Init(); { for (int k = 0; k < 10000; k++) { Linklist.Remove(k); } } } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); { Init(); { for (int k = 0; k < 10000; k++) { _List.Remove(k); } } } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); Console.ReadLine(); }
private static void RunWithContext(string topic, int iterations, Federation federation) { using (RequestContext.Create()) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null); stopwatch.Stop(); Console.WriteLine("Rendered first times in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F); stopwatch.Reset(); stopwatch.Start(); content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null); stopwatch.Stop(); Console.WriteLine("Rendered second time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F); stopwatch.Reset(); stopwatch.Start(); content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null); stopwatch.Stop(); Console.WriteLine("Rendered third time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F); } }
public void ShouldPerformFasterThanActivator() { // warmup for (var i = 0; i < 10; ++i) { Activator.CreateInstance<ClassWithDefaultConstuctor>(); ReflectionHelpers.CreateInstance<ClassWithDefaultConstuctor>(); } // warmup var count = 0; var stopWatch = new Stopwatch(); stopWatch.Start(); for (var i = 0; i < 1000000; ++i) { count += ReflectionHelpers.CreateInstance<ClassWithDefaultConstuctor>().Value; } stopWatch.Stop(); var creatorTime = stopWatch.Elapsed; stopWatch.Reset(); stopWatch.Start(); for (var i = 0; i < 1000000; ++i) { count += Activator.CreateInstance<ClassWithDefaultConstuctor>().Value; } stopWatch.Stop(); var activator = stopWatch.Elapsed; Assert.IsTrue(creatorTime < activator); Assert.AreEqual(2000000, count); }
public void TestCutLargeFile() { var weiCheng = File.ReadAllText(@"Resources\围城.txt"); var seg = new JiebaSegmenter(); seg.Cut("热身"); Console.WriteLine("Start to cut"); var n = 20; var stopWatch = new Stopwatch(); // Accurate mode stopWatch.Start(); for (var i = 0; i < n; i++) { seg.Cut(weiCheng); } stopWatch.Stop(); Console.WriteLine("Accurate mode: {0} ms", stopWatch.ElapsedMilliseconds / n); // Full mode stopWatch.Reset(); stopWatch.Start(); for (var i = 0; i < n; i++) { seg.Cut(weiCheng, true); } stopWatch.Stop(); Console.WriteLine("Full mode: {0} ms", stopWatch.ElapsedMilliseconds / n); }
public static void run(Action testMethod, int rounds){ Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); while (stopwatch.ElapsedMilliseconds < 1200) // A Warmup of 1000-1500 mS // stabilizes the CPU cache and pipeline. { testMethod(); // Warmup clearMemory (); } stopwatch.Stop(); long totalmem; Console.WriteLine ("Round;Runtime ms;Memory KB"); for (int repeat = 0; repeat < rounds; ++repeat) { stopwatch.Reset(); stopwatch.Start(); testMethod(); stopwatch.Stop(); totalmem = getUsedMemoryKB (); clearMemory (); Console.WriteLine((1+repeat)+";"+stopwatch.ElapsedMilliseconds + ";" +totalmem); } }
public static void TestProgram() { var sw = new Stopwatch(); sw.Start(); Console.WriteLine("Fi(30) = {0} - slow", CalculateNthFi(30)); sw.Stop(); Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); Console.WriteLine("Fi(30) = {0} - fast", CalculateNthFi2(30)); sw.Stop(); Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); Console.WriteLine("Fi(30) = {0} - fast2", CalculateNthFi3(30, 0, 1, 1)); sw.Stop(); Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds); Console.WriteLine(""); }
public void BinaryStressTest() { var b = new Truck("MAN"); var upper = Math.Pow(10, 3); var sw = new Stopwatch(); sw.Start(); b.LoadCargo(BinaryTestModels.ToList()); sw.Stop(); var secondElapsedToAdd = sw.ElapsedMilliseconds; Trace.WriteLine(string.Format("Put on the Channel {1} items. Time Elapsed: {0}", secondElapsedToAdd, upper)); sw.Reset(); sw.Start(); b.DeliverTo("Dad"); sw.Stop(); var secondElapsedToBroadcast = sw.ElapsedMilliseconds ; Trace.WriteLine(string.Format("Broadcast on the Channel {1} items. Time Elapsed: {0}", secondElapsedToBroadcast, upper)); var elem = b.UnStuffCargo<List<BinaryTestModel>>().First(); Assert.AreEqual(elem.Count(), 1000, "Not every elements have been broadcasted"); Assert.IsTrue(secondElapsedToAdd < 5000, "Add took more than 5 second. Review the logic, performance must be 10000 elems in less than 5 sec"); Assert.IsTrue(secondElapsedToBroadcast < 3000, "Broadcast took more than 3 second. Review the logic, performance must be 10000 elems in less than 5 sec"); }
public void CopyConstructorSpeed() { var random = new Random(); var values = new double[5000000]; for (var i = 0; i < 5000000; i++) { values[i] = random.Next(); } var scalarSet = new ScalarSet(values); // copying values var stopwatch = new Stopwatch(); stopwatch.Start(); values.Clone(); stopwatch.Stop(); var copyArrayTime = stopwatch.ElapsedMilliseconds; Trace.WriteLine("Copying array with 1M values took: " + copyArrayTime + " ms"); stopwatch.Reset(); stopwatch.Start(); new ScalarSet(scalarSet); stopwatch.Stop(); Trace.WriteLine("Copying scalar set with 1M values took: " + stopwatch.ElapsedMilliseconds + " ms"); var fraction = stopwatch.ElapsedMilliseconds/copyArrayTime; Assert.IsTrue(fraction < 1.1); }
// Use this for initialization void Start() { if (SVGFile != null) { Stopwatch w = new Stopwatch(); w.Reset(); w.Start(); ISVGDevice device; if(useFastButBloatedRenderer) device = new SVGDeviceFast(); else device = new SVGDeviceSmall(); m_implement = new Implement(this.SVGFile, device); w.Stop(); long c = w.ElapsedMilliseconds; w.Reset(); w.Start(); m_implement.StartProcess(); w.Stop(); long p = w.ElapsedMilliseconds; w.Reset(); w.Start(); renderer.material.mainTexture = m_implement.GetTexture(); w.Stop(); long r = w.ElapsedMilliseconds; UnityEngine.Debug.Log("Construction: " + Format(c) + ", Processing: " + Format(p) + ", Rendering: " + Format(r)); Vector2 ts = renderer.material.mainTextureScale; ts.x *= -1; renderer.material.mainTextureScale = ts; renderer.material.mainTexture.filterMode = FilterMode.Trilinear; } }
static void Main(string[] args) { Bootstrapper bootstrapper = Bootstrapper.Create() .RegisterInstaller(new ResourceBuilderInstaller()) .RegisterInstaller(new StructInstaller()) .RegisterInstaller(new ServiceInstaller()); string chittinKeyPath = Path.Combine(@"C:\Program Files (x86)\Baldur's Gate Enhanced Edition\Data\00766", "CHITIN.KEY"); string dialogPath = Path.Combine(@"C:\Program Files (x86)\Baldur's Gate Enhanced Edition\Data\data\lang\en_US", "dialog.tlk"); var resourceFileProvider = bootstrapper.WindsorContainer.Resolve<IResourceFileProvider>(); byte[] contentOfFile = resourceFileProvider.GetByteContentOfFile(chittinKeyPath); IKeyResourceBuilder keyResourceBuilder = bootstrapper.WindsorContainer.Resolve<IKeyResourceBuilder>(); //IDlgResourceBuilder dlgResourceBuilder = bootstrapper.WindsorContainer.Resolve<IDlgResourceBuilder>(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); KeyResource keyResource = keyResourceBuilder.BuildKeyResource(contentOfFile); stopwatch.Stop(); Console.WriteLine("Miliseconds : {0} - Ticks {1}", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks); stopwatch.Reset(); stopwatch.Start(); KeyResource buildKeyResourceNew = keyResourceBuilder.BuildKeyResourceNew(contentOfFile); stopwatch.Stop(); Console.WriteLine("Miliseconds : {0} - Ticks {1}", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks); Console.ReadLine(); }
public void WillWaitForItem() { using (var queue = GetQueue()) { queue.DeleteQueue(); TimeSpan timeToWait = TimeSpan.FromSeconds(1); var sw = new Stopwatch(); sw.Start(); var workItem = queue.Dequeue(timeToWait); sw.Stop(); Trace.WriteLine(sw.Elapsed); Assert.Null(workItem); Assert.True(sw.Elapsed > timeToWait.Subtract(TimeSpan.FromMilliseconds(10))); Task.Factory.StartNewDelayed(100, () => queue.Enqueue(new SimpleWorkItem { Data = "Hello" })); sw.Reset(); sw.Start(); workItem = queue.Dequeue(timeToWait); workItem.Complete(); sw.Stop(); Trace.WriteLine(sw.Elapsed); Assert.NotNull(workItem); } }
public void ECPerformanceTest() { Stopwatch sw = new Stopwatch(); int timesofTest = 1000; string[] timeElapsed = new string[2]; string testCase = "sdg;alwsetuo1204985lkscvzlkjt;"; sw.Start(); for(int i = 0; i < timesofTest; i++) { this.Encode(testCase, 3); } sw.Stop(); timeElapsed[0] = sw.ElapsedMilliseconds.ToString(); sw.Reset(); sw.Start(); for(int i = 0; i < timesofTest; i++) { this.ZXEncode(testCase, 3); } sw.Stop(); timeElapsed[1] = sw.ElapsedMilliseconds.ToString(); Assert.Pass("EC performance {0} Tests~ QrCode.Net: {1} ZXing: {2}", timesofTest, timeElapsed[0], timeElapsed[1]); }
public void Test_perf_of_query_without_index() { OdbFactory.Delete("index1perf.ndb"); using (var odb = OdbFactory.Open("index1perf.ndb")) { for (var i = 0; i < 5000; i++) { var player = new Player("Player" + i, DateTime.Now, new Sport("Sport" + i)); odb.Store(player); } } var stopwatch = new Stopwatch(); stopwatch.Start(); using (var odb = OdbFactory.OpenLast()) { var query = odb.Query<Player>(); query.Descend("Name").Constrain((object) "Player20").Equal(); var count = query.Execute<Player>().Count; Assert.That(count, Is.EqualTo(1)); } stopwatch.Stop(); Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); using (var odb = OdbFactory.OpenLast()) { var query = odb.Query<Player>(); query.Descend("Name").Constrain((object) "Player1234").Equal(); var count = query.Execute<Player>().Count; Assert.That(count, Is.EqualTo(1)); } stopwatch.Stop(); Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); using (var odb = OdbFactory.OpenLast()) { var query = odb.Query<Player>(); query.Descend("Name").Constrain((object) "Player4444").Equal(); var count = query.Execute<Player>().Count; Assert.That(count, Is.EqualTo(1)); } stopwatch.Stop(); Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); using (var odb = OdbFactory.OpenLast()) { var query = odb.Query<Player>(); query.Descend("Name").Constrain((object) "Player3211").Equal(); var count = query.Execute<Player>().Count; Assert.That(count, Is.EqualTo(1)); } stopwatch.Stop(); Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds); }
public void ComputeTimesPrimes() { Stopwatch w = new Stopwatch(); w.Start(); PrimeNumbers.GeneratePrimeNumbers1(100000); Console.WriteLine("Primes 1: " + w.ElapsedMilliseconds.ToString()); w.Stop(); w.Reset(); w.Start(); PrimeNumbers.GeneratePrimeNumbers2(100000); Console.WriteLine("Primes 2: "+ w.ElapsedMilliseconds.ToString()); w.Stop(); w.Reset(); w.Start(); PrimeNumbers.GeneratePrimeNumbers3(100000); Console.WriteLine("Primes 3: " + w.ElapsedMilliseconds.ToString()); w.Stop(); w.Start(); for (int i = 1; i <= 100000; i++) { int mod = i % 2; } w.Stop(); Console.WriteLine("Primes 4: " + w.ElapsedMilliseconds.ToString()); }
private int FindAndSaveApps(ICollection<int> partition) { ICollection<App> apps = appParser.RetrieveApps(partition); if (apps == null) { return 0; } Stopwatch watch = new Stopwatch(); watch.Start(); foreach (App app in apps) { repository.App.Save(app); indexer.AddApp(app); } watch.Stop(); logger.Debug("Saved {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); indexer.Flush(); watch.Stop(); logger.Debug("Indexed {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds); return apps.Count; }
private static void Main() { // Testing different type of reverse algorithms Stopwatch timeTest = new Stopwatch(); Console.Write("Enter some string: "); string str = Console.ReadLine(); // Using StringBuilder timeTest.Start(); string reversed = ReverseSB(str); timeTest.Stop(); Console.WriteLine("Reverse text: {0}\ntime: {1} - StringBuilder class", reversed, timeTest.Elapsed); timeTest.Reset(); Console.WriteLine(); // Using Array.Reverse timeTest.Start(); string reversedArrayReverse = ReverseArray(str); timeTest.Stop(); Console.WriteLine("Reverse text: {0}\ntime: {1} - Array.Reverse", reversedArrayReverse, timeTest.Elapsed); timeTest.Reset(); Console.WriteLine(); // Using XOR timeTest.Start(); string reversedXor = ReverseXor(str); timeTest.Stop(); Console.WriteLine("Reverse text: {0}\ntime: {1} - XOR", reversedXor, timeTest.Elapsed); timeTest.Reset(); }
static void Main(string[] args) { string data = File.ReadAllText(@"....."); Stopwatch watch = new Stopwatch(); for (int i = 0; i < 20; i++) { watch.Start(); Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(data); watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); } Console.WriteLine(" "); GC.Collect(); for (int i = 0; i < 20; i++) { watch.Start(); JParser parser = new JParser(); JToken token = parser.Parse(data); watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); } Console.WriteLine(" "); }