Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: FormatBenchmark <rootPath> <format>");

                return;
            }

            string rootPath = args[0];
            string format   = args[1];

            try
            {
                IrbisEncoding.RelaxUtf8();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    provider.Database = "IBIS";
                    int maxMfn = provider.GetMaxMfn();
                    Console.WriteLine("Max MFN={0}", maxMfn);

                    PftContext context = new PftContext(null);
                    context.SetProvider(provider);
                    PftFormatter formatter = new PftFormatter(context);
                    formatter.ParseProgram(format);

                    for (int mfn = 1; mfn <= maxMfn; mfn++)
                    {
                        MarcRecord record = provider.ReadRecord(mfn);
                        if (ReferenceEquals(record, null))
                        {
                            continue;
                        }

                        string text = formatter.FormatRecord(record);
                        Console.WriteLine(text);
                    }
                }

                stopwatch.Stop();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine
                (
                    "Elapsed: {0} sec",
                    stopwatch.Elapsed.ToSecondString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                return;
            }

            string rootPath   = args[0];
            string formatName = args[1];

            try
            {
                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    FileSpecification specification = new FileSpecification
                                                      (
                        IrbisPath.MasterFile,
                        provider.Database,
                        formatName
                                                      );
                    string source = provider.ReadFile(specification);
                    if (string.IsNullOrEmpty(source))
                    {
                        Console.WriteLine("No file: {0}", formatName);
                    }
                    else
                    {
                        PftContext context = new PftContext(null);
                        context.SetProvider(provider);
                        PftFormatter formatter = new PftFormatter(context);
                        formatter.ParseProgram(source);

                        PftProgram program
                            = (PftProgram)formatter.Program.Clone();
                        program.Optimize();

                        //Console.WriteLine(program.DumpToText());
                        //Console.WriteLine();

                        if (!Directory.Exists("Out"))
                        {
                            Directory.CreateDirectory("Out");
                        }

                        PftCompiler compiler = new PftCompiler
                        {
                            Debug      = true,
                            KeepSource = true,
                            //OutputPath = "Out"
                            OutputPath = "."
                        };
                        compiler.SetProvider(provider);
                        string className = compiler.CompileProgram
                                           (
                            program
                                           );

                        //string sourceCode = compiler.GetSourceCode();
                        //Console.WriteLine(sourceCode);

                        AbstractOutput output       = AbstractOutput.Console;
                        string         assemblyPath = compiler.CompileToDll
                                                      (
                            output,
                            className
                                                      );
                        if (!ReferenceEquals(assemblyPath, null))
                        {
                            Console.WriteLine
                            (
                                "Compiled to {0}",
                                assemblyPath
                            );

                            MarcRecord record = provider.ReadRecord(1);

                            //if (!ReferenceEquals(record, null))
                            //{
                            //    Assembly assembly
                            //        = Assembly.LoadFile(assemblyPath);
                            //    Func<PftContext, PftPacket> creator
                            //        = CompilerUtility.GetEntryPoint(assembly);
                            //    PftPacket packet = creator(context);
                            //    string formatted = packet.Execute(record);
                            //    Console.WriteLine(formatted);

                            //    Stopwatch stopwatch = new Stopwatch();
                            //    stopwatch.Start();
                            //    for (int i = 0; i < 100000; i++)
                            //    {
                            //        if (i % 1000 == 0)
                            //        {
                            //            Console.WriteLine(i);
                            //        }
                            //        packet.Execute(record);
                            //    }
                            //    stopwatch.Stop();
                            //    Console.WriteLine(stopwatch.Elapsed);
                            //}

                            if (!ReferenceEquals(record, null))
                            {
                                using (RemoteFormatter remote
                                           = new RemoteFormatter(assemblyPath))
                                {
                                    PftPacket packet = remote.GetFormatter(context);
                                    Console.WriteLine(RemotingServices.IsTransparentProxy(packet));
                                    string formatted = packet.Execute(record);
                                    Console.WriteLine(formatted);

                                    Stopwatch stopwatch = new Stopwatch();
                                    stopwatch.Start();
                                    for (int i = 0; i < 100; i++)
                                    {
                                        if (i % 10 == 0)
                                        {
                                            Console.WriteLine(i);
                                        }
                                        packet.Execute(record);
                                    }
                                    stopwatch.Stop();
                                    Console.WriteLine(stopwatch.Elapsed);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }