Esempio n. 1
0
        private static void Benchmark(
            TextWriter writer,
            int size,
            bool readOnly,
            bool sortBeforeSplit
            )
        {
            const string stopwatchFmt = "\t{0}ms";
            var          filename     = string.Format("students{0}", size);

            if (!readOnly)
            {
                writer.WriteLine("Generating file {0}", filename);
                using (new DisposableStopwatch(t => writer.WriteLine(stopwatchFmt, t))) {
                    GenerateStudentsFile(filename, size);
                }
            }

            var store = new ListBasedStudentStore(size);

            writer.WriteLine("Reading data");
            using (new DisposableStopwatch(t => writer.WriteLine(stopwatchFmt, t))) {
                AddStudentsFromFile(writer, filename, store);
            }

            if (sortBeforeSplit)
            {
                writer.WriteLine("Sorting by final grade");
                using (new DisposableStopwatch(t => writer.WriteLine(stopwatchFmt, t))) {
                    store.SortByFinalGrade();
                }
            }

            IEnumerable <Student> failed;
            IEnumerable <Student> passed;

            writer.WriteLine("Splitting into failed / passed");
            using (new DisposableStopwatch(t => writer.WriteLine(stopwatchFmt, t))) {
                var failedPassed = store.SplitFailedPassed();
                failed = failedPassed.Item1;
                passed = failedPassed.Item2;
            }

            var failedFilename = filename + "_failed";
            var passedFilename = filename + "_passed";

            writer.WriteLine("Writing to {0} / {1}", failedFilename, passedFilename);
            using (new DisposableStopwatch(t => writer.WriteLine(stopwatchFmt, t))) {
                WriteStudentsToFile(failedFilename, failed);
                WriteStudentsToFile(passedFilename, passed);
            }

            writer.WriteLine();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var io       = new InteractiveIO(Console.In, Console.Out);
            var students = new ListBasedStudentStore(10);

            BranchMenu(
                Console.In,
                Console.Out,
                Console.Clear,
                io,
                students
                );
        }