Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int       numberOfRabbits = 1000;
            Random    rand            = new Random();
            Stopwatch sw = new Stopwatch();

            //stopwatch

            //one read

            //Console.WriteLine($"Time taken for one read {sw.Elapsed}");
            //sw.Stop();
            //sw.Reset();
            //1000 seperate reads

            //Console.WriteLine($"Time taken for 1000 reads {sw.Elapsed}");
            //sw.Stop();

            using (var db = new RabbitDbEntities())
            {
                sw.Start();
                foreach (Rabbit rabbit in db.Rabbits.ToList())
                {
                    Console.WriteLine(rabbit.RabbitID);
                }
            }

            var OneTime = sw.Elapsed.ToString();

            sw.Stop();
            sw.Reset();

            for (int i = 1; i <= numberOfRabbits; i++)
            {
                sw.Start();
                using (var db = new RabbitDbEntities())
                {
                    Console.WriteLine(db.Rabbits.Find(i).RabbitID);
                }
            }

            var ThousandTimes = sw.Elapsed.ToString();

            sw.Stop();

            Console.WriteLine($"Time taken for 1 read {OneTime}");
            Console.WriteLine($"Time taken for 1000 reads {ThousandTimes}");

            Console.ReadLine();
            //report times to console DONE
            //report times to CSV
            File.WriteAllText("RabbitOutput.CSV", "//log of new rabbit");
            File.AppendAllText("RabbitOutput.CSV", $"\n1,Billy,12");
            File.AppendAllText("RabbitOutput.CSV", $"\n2,Fluffy,13");
            Process.Start("RabbitOutput.CSV");
            //report times to Word
            //do that in wpf
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var timer = new Stopwatch();

            int numberOfRabbitsToCreate = 1000;


            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    var newRabbit = new Rabbit();
                    db.Rabbits.Add(newRabbit);
                    db.SaveChanges();
                }
            }

            //timer.Stop();
            //Console.WriteLine("1 read took: " + timer.ElapsedMilliseconds);
            // one read
            timer.Start();

            using (var db = new RabbitDbEntities())
            {
                rabbits = db.Rabbits.ToList();
            }
            timer.Stop();

            Console.WriteLine("1 Read took: " + timer.ElapsedMilliseconds + "Milliseconds");


            timer.Restart();
            // 1000 reads
            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    Rabbit newRabbit = db.Rabbits.Find(i + 1);
                    //Rabbit newRabbit = db.Rabbits.ToList()[i];
                    rabbits.Add(newRabbit);
                }
            }
            timer.Stop();
            Console.WriteLine("1000 reads took: " + timer.ElapsedMilliseconds);


            // REPORT TIMES TO CONSOLE
            // REPORT TIMES TO CSV
            File.WriteAllText("Rabbits.csv", "ID,Name,Age");
            File.AppendAllText("Rabbits.csv", "\n1,Billy,12");
            File.AppendAllText("Rabbits.csv", "\n2,Fluffy,13");
            Process.Start("Rabbits.csv");
            Console.ReadKey();
            // REPORT TIMES TO WORD
            // SPRINT 2: move everything to WPF
        }
Ejemplo n.º 3
0
        static void AddBunnies()
        {
            var newRabbit = new Rabbit()
            {
                Age        = 0,
                RabbitName = $"Rabbit whatever"
            };

            using (var db = new RabbitDbEntities())
            {
                db.Rabbits.Add(newRabbit);
                db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void PopRabbitDb1(int numberOfRabbits)
        {
            Random rand = new Random();

            using (var db = new RabbitDbEntities())
            {
                for (int i = 0; i < numberOfRabbits; i++)
                {
                    Rabbit rb = new Rabbit();
                    rb.Age  = rand.Next(21);
                    rb.Name = $"Jeff{i}";
                    db.Rabbits.Add(rb);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //stopwatch
            var s = new Stopwatch();

            s.Start();

            int numberOfRabbitsToCreate = 1003;

            //one read
            //using (var db = new RabbitDbEntities())
            //{
            //    rabbits = db.Rabbits.ToList();

            //}


            rabbits = new List <Rabbit>();
            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    //AddBunnies();
                    db.Rabbits.ToList();
                    var rabbit = (Rabbit)db.Rabbits.Find(i + 1);
                    rabbits.Add(rabbit);
                }
            }
            PrintRabbits();

            s.Stop();
            Console.WriteLine(s.Elapsed + " seconds");
            //Console.WriteLine(s.ElapsedMilliseconds + " milliseconds");

            //report times to console
            //report times to CSV
            File.WriteAllText("RabbitOutPut.csv", "Id,Name,Age");
            File.AppendAllText("RabbitOutPut.csv", "\n1,Billy,12"); //or do Environment.Newline
            File.AppendAllText("RabbitOutPut.csv", "\n2,Fluffy,13");
            Process.Start("RabbitOutput.csv");

            //report times to Word
            //sprint 2: move everything to WPF
        }
        static void Main(string[] args)
        {
            int numberOfRabbitsToCreate = 1000;

            // stopwatch

            // one read
            using (var db = new RabbitDbEntities()) { }
            // 1000 reads
            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                }
            }
            // report times to console
            // report times to CSV
            File.WriteAllText("RabbitOutput.csv", "ID,Name,Age");
            File.AppendAllText("RabbitOutput.csv", "\n1,Billy,12");  // Environment.NewLine
            File.AppendAllText("RabbitOutput.csv", "\n2,Fluffy,13");
            Process.Start("RabbitOutput.csv");
            // report times to Word
            // Sprint 2 : move everything to WPF!!!
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            int       noOfRabbitsToCreate = 1000;
            Stopwatch stopwatch = new Stopwatch();
            String    firstTimeElapsed, secondTimeElapsed;

            //for (int i = 1; i <= noOfRabbitsToCreate; i++)
            //{
            //    using (var db = new RabbitDbEntities())
            //    {
            //        var rabbit = new Rabbit();
            //        db.Rabbits.Add(rabbit);
            //        db.SaveChanges();
            //    }
            //}

            //using (var db = new RabbitDbEntities())
            //{
            //    for (int i = 1; i <= noOfRabbitsToCreate; i++)
            //    {

            //        var rabbit = new Rabbit();
            //        db.Rabbits.Add(rabbit);
            //        db.SaveChanges();
            //    }
            //}



            stopwatch.Start();
            using (var db = new RabbitDbEntities())
            {
                for (int i = 1; i <= noOfRabbitsToCreate; i++)
                {
                    Console.WriteLine(db.Rabbits.Find(i).RabbitID);
                }
            }

            firstTimeElapsed = stopwatch.Elapsed.ToString();
            stopwatch.Stop();
            stopwatch.Reset();

            stopwatch.Start();
            using (var db = new RabbitDbEntities())
            {
                foreach (var rabbit in db.Rabbits.ToList())
                {
                    Console.WriteLine(rabbit.RabbitID);
                }
            }

            firstTimeElapsed = stopwatch.Elapsed.ToString();
            stopwatch.Stop();
            stopwatch.Reset();


            stopwatch.Start();
            for (int i = 1; i <= noOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    Console.WriteLine(db.Rabbits.Find(i).RabbitID);
                }
            }

            secondTimeElapsed = stopwatch.Elapsed.ToString();
            stopwatch.Stop();
            stopwatch.Reset();



            File.WriteAllText("rabbits.csv", "ID,Name,Age");
            File.AppendAllText("rabbits.csv", "\n1, Billy, 12");
            File.AppendAllText("rabbits.csv", "\n2, Bob, 9");
            Process.Start("rabbits.csv");

            //Console.WriteLine($"1 read time elapsed = {firstTimeElapsed}");
            //Console.WriteLine($"1000 read time elapsed = {secondTimeElapsed}");
            Console.ReadLine();
        }