Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Write("{0}{1}",
                          "\n  Time Parsing Operations ",
                          "\n =========================\n"
                          );

            OpTimer ot = new OpTimer();

            ot.Verbose = false;
            string fileName = "../../Test.cs";

            ot.ParseFile(fileName);

            HiResTimer hrt = new HiResTimer();

            hrt.Start();
            int N = 1000;

            for (int i = 0; i < N; ++i)
            {
                ot.HashLookUp("class");
            }
            hrt.Stop();
            ulong lookUpTime = hrt.ElapsedMicroseconds;

            Console.Write("\n   {0} lookups took {1} microseconds", N, lookUpTime);
            Console.Write("\n\n");
            ot.showTable();
            Console.Write("\n\n");
        }
Ejemplo n.º 2
0
        //-------------< test stub >-----------
        static void Main(string[] args)
        {
            HiResTimer hrt = new HiResTimer();
            PerfTest   pt  = new PerfTest();

            for (int j = 0; j < 10; j++)
            {
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("add", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("edit", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("delete", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("persist", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("restore", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("value", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("children", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("pattern", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("string", hrt.ElapsedMicroseconds);
                }
                hrt.Start();
                for (int i = 0; i < 10; i++)
                {
                    hrt.Stop();
                    pt.add("interval", hrt.ElapsedMicroseconds);
                }
            }
            pt.printTimes();
        }
        static void Main(string[] args)
        {
            WriteRequestParser re = new WriteRequestParser();

            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");

            Console.Title = "Write Client";

            WriteClient clnt = new WriteClient();

            clnt.processCommandLine(args);

            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }

            Sender sndr = new Sender(clnt.localUrl); // Sender needs localUrl for start message

            Message msg = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;

            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }
            clnt.request = re.parse("writeRequest.xml");
            HiResTimer hrt   = new HiResTimer();
            ulong      total = 0;

            foreach (string i in clnt.request)
            {
                msg         = new Message();
                msg.fromUrl = clnt.localUrl;
                msg.toUrl   = clnt.remoteUrl;
                msg.content = i;
                if (clnt.verbose == 1)
                {
                    Console.Write("\n  Sending: {0}", msg.content);
                }
                hrt.Start();
                if (!sndr.sendMessage(msg))
                {
                    break;
                }
                hrt.Stop();
                total += hrt.ElapsedMicroseconds;
                Thread.Sleep(100);
            }
            //hrt.Stop();

            /*Use the following for testing the client
             *
             * int numMsgs = 5;
             * int counter = 0;
             * while (true)
             * {
             *      msg.content = "Hello";
             *      Console.Write("\n  sending {0}", msg.content);
             *      if (!sndr.sendMessage(msg))
             *              return;
             *      Thread.Sleep(100);
             ++counter;
             *      if (counter >= numMsgs)
             *              break;
             * }
             *
             */
            Console.Write("\n  Total time taken for sending all write messages {0} microseconds\n", total);
            msg         = new Message();
            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;
            msg.content = "done";
            sndr.sendMessage(msg);

            // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            Util.waitForUser();

            // shut down this client's Receiver and Sender by sending close messages
            try { rcvr.shutDown();
                  sndr.shutdown(); }
            catch { Console.Write("\n  Problem with closing sender and/or receiver\n"); }

            Console.Write("\n\n");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            RequestEngine      re  = new RequestEngine();
            QueryRequestEngine qre = new QueryRequestEngine();
            DBEngine <string, DBElement <string, List <string> > > db = new DBEngine <string, DBElement <string, List <string> > >();

            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);

            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");

            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            //Sender sndr = new Sender();
            Receiver rcvr = new Receiver(srvr.port, srvr.address);

            // - serviceAction defines what the server does with received messages
            // - This serviceAction just announces incoming messages and echos them
            //   back to the sender.
            // - Note that demonstrates sender routing works if you run more than
            //   one client.
            HiResTimer hrt           = new HiResTimer();
            PerfTest   pt            = new PerfTest();
            Action     serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage();                       // note use of non-service method to deQ messages
                    //insert();
                    int    length = msg.content.IndexOf(",") + 1;
                    string from   = "";
                    if (msg.content != "connection start message")
                    {
                        from = msg.content.Substring(0, length);                         //figure out where the request came from
                    }
                    string[] msgList = msg.content.Split(',');
                    Console.Write("\n  Received message:");
                    Console.Write("\n  Request type is: {0}", from);                     //denotes where the request came from
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    Console.Write("\n  content is {0}\n", msg.content);
                    string reply = "";
                    //------------< do processing based on the request type >------------
                    if (from == "write,")
                    {
                        hrt.Start();
                        re.parseRequest(msg.content, out reply);
                        hrt.Stop();
                        pt.add(msgList[1], hrt.ElapsedMicroseconds);
                        msg.content = reply;
                    }
                    else if (from == "read,")
                    {
                        hrt.Start();
                        db = re.getDB();
                        qre.parseRequest(db, msg.content, out reply);
                        hrt.Stop();
                        pt.add(msgList[1], hrt.ElapsedMicroseconds);
                        msg.content = reply;
                    }
                    else if (from == "perf,")
                    {
                        reply       = pt.printTimesWpf(msgList[1]);
                        msg.content = reply;
                    }
                    if (msg.content == "connection start message")
                    {
                        continue;                         // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        Console.WriteLine(pt.printTimes());
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    // swap urls for outgoing message
                    Util.swapUrls(ref msg);

#if (TEST_WPFCLIENT)
                    /////////////////////////////////////////////////
                    // The statements below support testing the
                    // WpfClient as it receives a stream of messages
                    // - for each message received the Server
                    //   sends back 1000 messages
                    // Use the code to test the server

                    /*int count = 0;
                     * for (int i = 0; i < 1000; ++i)
                     * {
                     *      Message testMsg = new Message();
                     *      testMsg.toUrl = msg.toUrl;
                     *      testMsg.fromUrl = msg.fromUrl;
                     *      testMsg.content = String.Format("test message #{0}", ++count);
                     *      Console.Write("\n  sending testMsg: {0}", testMsg.content);
                     *      sndr.sendMessage(testMsg);
                     * }*/
                    Message testMsg = new Message();
                    testMsg.toUrl   = msg.toUrl;
                    testMsg.fromUrl = msg.fromUrl;
                    testMsg.content = String.Format("test message");
                    Console.Write("\n  sending testMsg: {0}", testMsg.content);
                    sndr.sendMessage(testMsg);
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    sndr.sendMessage(msg);
                    //re.db.show<string, DBElement<string, List<string>>, List<string>, string>();
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction);           // This serviceAction is asynchronous,
            }                                            // so the call doesn't block.
            Util.waitForUser();
        }
Ejemplo n.º 5
0
        //
        //----< parse file into identifiers and store in Hashtable >-------

        public void ParseFile(string fileName)
        {
            HiResTimer total = new HiResTimer();
            HiResTimer open  = new HiResTimer();
            HiResTimer parse = new HiResTimer();

            try
            {
                total.Start();
                open.Start();
                StreamReader fs = new StreamReader(fileName);
                open.Stop();
                openTime = open.ElapsedMicroseconds;

                parse.Start();
                int    size = 0;
                string line;
                while ((line = fs.ReadLine()) != null)
                {
                    string[] tokens = line.Split();
                    foreach (string token in tokens)
                    {
                        if (token == "\n" | token.Length == 0)
                        {
                            continue;
                        }
                        if (Verbose)
                        {
                            Console.Write("\n    {0}", token);
                        }
                        string tok, compositeToken = token;
                        while (compositeToken != "")
                        {
                            tok = extractIdent(ref compositeToken);
                            if (tok == "")
                            {
                                continue;
                            }
                            if (Verbose)
                            {
                                Console.Write("\n      {0}", tok);
                            }
                            if (table.Contains(tok))
                            {
                                table[tok] = 1 + (int)table[tok];
                            }
                            else
                            {
                                table[tok] = 1;
                                size      += tok.Length;
                            }
                        }
                    }
                }
                parse.Stop();
                parseTime = parse.ElapsedMicroseconds;
                total.Stop();
                totalTime = total.ElapsedMicroseconds;

//
                Console.Write("\n   Open time: {0} microsec", openTime);
                Console.Write("\n  Parse time: {0} microsec", parseTime);
                Console.Write("\n  total time: {0} microsec", totalTime);
                Console.Write("\n   Hash size: {0} bytes", size);
            }
            catch
            {
                Console.Write("\n  Could not open file \"{0}\"\n\n", fileName);
            }
        }