Esempio n. 1
0
        public override void Run()
        {
            MarkProfile("Reading story");

            var bytes = File.ReadAllBytes(StoryFilePath);

            CompiledZMachine machine    = null;
            Action           doneAction = () => { throw new ZMachineInterruptedException(); };

            var mockScreen = new MockScreen(ScriptFilePath, doneAction);

            machine = new CompiledZMachine(Story.FromBytes(bytes), profiler: profile ? this : null);
            machine.RegisterScreen(mockScreen);
            machine.SetRandomSeed(42);

            MarkProfile("Running...");

            watch = Stopwatch.StartNew();

            try
            {
                machine.Run();
            }
            catch (ZMachineQuitException)
            {
                // done
            }
            catch (ZMachineInterruptedException)
            {
                // done
            }
            catch (Exception ex)
            {
                MarkProfile(string.Format("{0}: {1}", ex.GetType().FullName, ex.Message));
            }

            watch.Stop();

            MarkProfile("Done");

            if (profile)
            {
                Console.WriteLine();
                Console.WriteLine("{0:#,#} instructions", instructionCount);
                Console.WriteLine("{0:#,#} calls", callCount);
            }
            Console.WriteLine();
            Console.WriteLine("{0:#,0.##########} seconds", (double)watch.ElapsedTicks / (double)Stopwatch.Frequency);
            if (profile)
            {
                Console.WriteLine("{0:#,0.##########} seconds per instruction", ((double)watch.ElapsedTicks / (double)Stopwatch.Frequency) / (double)instructionCount);
            }
        }
Esempio n. 2
0
        public override void Run()
        {
            MarkProfile("Reading story");

            var story     = ReadStory(StoryFilePath);
            var processor = new InterpretedZMachine(story);

            var    done       = false;
            Action doneAction = () => { done = true; };

            var mockScreen = new MockScreen(ScriptFilePath, doneAction);

            processor.SetRandomSeed(42);
            processor.RegisterScreen(mockScreen);

            processor.Quit += (s, e) => { done = true; };

            MarkProfile("Stepping...");

            var sw = Stopwatch.StartNew();

            try
            {
                while (!done)
                {
                    processor.Step();
                }
            }
            catch (Exception ex)
            {
                MarkProfile(string.Format("{0}: {1}", ex.GetType().FullName, ex.Message));
            }

            sw.Stop();

            MarkProfile("Done stepping");

            Console.WriteLine();
            Console.WriteLine("{0:#,#} instructions", processor.InstructionCount);
            Console.WriteLine("{0:#,#} calls", processor.CallCount);
            Console.WriteLine();
            Console.WriteLine("{0:#,0.##########} seconds", (double)sw.ElapsedTicks / (double)Stopwatch.Frequency);
            Console.WriteLine("{0:#,0.##########} seconds per instruction", ((double)sw.ElapsedTicks / (double)Stopwatch.Frequency) / (double)processor.InstructionCount);
        }