Ejemplo n.º 1
0
    static StreamWriter logWriter = new StreamWriter(logFile);                                                              // The logging stream

    /*
     * Program entry point
     */
    static void Main(string[] args)
    {
        logWriter.AutoFlush = true;

        // Get access to sql
        string        connectionString = "Data Source=tcp:172.30.100.116;\n;Initial Catalog=GlobalDeviceService;\nUser ID=octopus;Password=octopus";
        SqlConnection cnn = new SqlConnection(connectionString);

        cnn.Open();

        // Load the queries
        string[] graphqlQueries = get_queries(numGraphQLQueries, GraphQLFolder);
        string[] sqlQueries     = get_queries(numSQLQueries, SQLFolder);

        // Process and time the queries for Graphql
        do_logging_writeline("Beginning GraphQL Tests\n");
        for (int i = 0; i < numGraphQLQueries && !String.IsNullOrEmpty(graphqlQueries[i]); i++)
        {
            // Do logging, start timer
            string curQuery = graphqlQueries[i];
            do_logging_writeline("Current Query: ");
            do_logging_write(curQuery + "\n\n");
            MicroLibrary.MicroStopwatch timer = new MicroLibrary.MicroStopwatch();

            // Get the result into the cache
            do_graphql_query_caching(curQuery).GetAwaiter().GetResult();

            // Time the query (cached) and sum the execution times
            long cachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_graphql_query_caching(curQuery).GetAwaiter().GetResult();
                timer.Stop();
                cachedTime += timer.ElapsedMicroseconds;
            }

            // Cleanup
            db.KeyDelete(curQuery);

            // Time the query (uncached) and sum the execution times
            long uncachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_graphql_query_no_caching(curQuery).GetAwaiter().GetResult();
                timer.Stop();
                uncachedTime += timer.ElapsedMicroseconds;
            }

            do_logging_writeline("Uncached execution time (Average of " + numExecutions.ToString() + " runs): " + (uncachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline("Cached execution time (Average of " + numExecutions.ToString() + " runs): " + (cachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline(((double)(uncachedTime / numExecutions) / (double)(cachedTime / numExecutions)).ToString() + " times faster.\n");
            //do_logging_writeline("Size of result set: " + result.Length.ToString() + "\n");
        }

        // Process and time the queries for SQL Server
        do_logging_writeline("\nBeginning SQL Tests\n");
        for (int i = 0; i < numSQLQueries && !String.IsNullOrEmpty(sqlQueries[i]); i++)
        {
            //Do logging, start timer
            string curQuery = sqlQueries[i];
            do_logging_writeline("Current Query: ");
            do_logging_write(curQuery + "\n\n");
            MicroLibrary.MicroStopwatch timer = new MicroLibrary.MicroStopwatch();

            // Get the result into the cache
            do_sql_query_caching(curQuery, cnn).GetAwaiter().GetResult();

            // Time the query (cached) and sum the execution times
            long cachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_sql_query_caching(curQuery, cnn).GetAwaiter().GetResult();
                timer.Stop();
                cachedTime += timer.ElapsedMicroseconds;
            }

            // Cleanup
            db.KeyDelete(curQuery);

            // Time the query (uncached) and sum the execution times
            long uncachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_sql_query_no_caching(curQuery, cnn).GetAwaiter().GetResult();
                timer.Stop();
                uncachedTime += timer.ElapsedMicroseconds;
            }

            do_logging_writeline("Uncached execution time (Average of " + numExecutions.ToString() + " runs): " + (uncachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline("Cached execution time (Average of " + numExecutions.ToString() + " runs): " + (cachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline(((double)(uncachedTime / numExecutions) / (double)(cachedTime / numExecutions)).ToString() + " times faster.\n");
            //do_logging_writeline("Size of result set: " + result.Length.ToString() + "\n");
        }

        // cleanup
        cnn.Close();
    }