private static void SubTestRun(StreamReader streamQueryParameters, int i1, IStore Store)
        {
            double[] results        = new double[12];
            double[] minimums       = Enumerable.Repeat(double.MaxValue, 12).ToArray();
            double[] maximums       = new double[12];
            double   maxMemoryUsage = 0;

            double[] totalparseMS = new double[12];
            double[] totalrun     = new double[12];
            for (int j = 0; j < i1; j++)
            {
                for (int i = 0; i < 12; i++)
                {
                    string file        = string.Format(@"..\..\examples\bsbm\queries\parameters\{0}.rq", i + 1);
                    var    readAllText = File.ReadAllText(file);
                    readAllText = BSBmParams.QueryReadParameters(readAllText, streamQueryParameters);

                    var timer = new Stopwatch();
                    SparqlQuery.SparqlClasses.Query.SparqlQuery sparqlQuery = null;
                    //  if (i == 0)
                    {
                        sparqlQuery = SparqlQueryParser.ParseSparql(Store, readAllText);
                    }

                    totalparseMS[i] += timer.GetTimeWthLast2Digits();
                    var st1 = DateTime.Now;
                    //if (i == 0)
                    {
                        var sparqlResultSet = sparqlQuery.Run().ToJson();
                    }
                    totalrun[i] += (DateTime.Now - st1).Ticks / 10000L;
                    var totalMilliseconds = timer.GetTimeWthLast2Digits();

                    var memoryUsage = GC.GetTotalMemory(false);
                    if (memoryUsage > maxMemoryUsage)
                    {
                        maxMemoryUsage = memoryUsage;
                    }
                    if (minimums[i] > totalMilliseconds)
                    {
                        minimums[i] = totalMilliseconds;
                    }
                    if (maximums[i] < totalMilliseconds)
                    {
                        maximums[i] = totalMilliseconds;
                    }
                    results[i] += totalMilliseconds;
                    //  File.WriteAllText(Path.ChangeExtension(file.FullName, ".txt"), resultString);
                    //.Save(Path.ChangeExtension(file.FullName,".xml"));
                }
            }
            using (StreamWriter r = new StreamWriter(@"..\..\output.txt", true))
            {
                r.WriteLine("milions " + 1);
                r.WriteLine("date time " + DateTime.Now);
                r.WriteLine("max memory usage " + maxMemoryUsage);
                r.WriteLine("average " + string.Join(", ", results.Select(l => l == 0 ? "inf" : (500 * 1000 / l).ToString())));
                r.WriteLine("minimums " + string.Join(", ", minimums));
                r.WriteLine("maximums " + string.Join(", ", maximums));
                r.WriteLine("total parse " + string.Join(", ", totalparseMS));
                r.WriteLine("total run " + string.Join(", ", totalrun));
                r.WriteLine("total " + totalparseMS.Sum() + totalrun.Sum());
                //    r.WriteLine("countCodingUsages {0} totalMillisecondsCodingUsages {1}", TripleInt.EntitiesCodeCache.Count, TripleInt.totalMilisecondsCodingUsages);

                //r.WriteLine("EWT average search" + EntitiesMemoryHashTable.total / EntitiesMemoryHashTable.count);
                //r.WriteLine("EWT average range" + EntitiesMemoryHashTable.totalRange / EntitiesMemoryHashTable.count);
            }
        }
Example #2
0
        public void Examples()
        {
            DirectoryInfo examplesRoot = new DirectoryInfo(@"..\..\examples");

            foreach (var exampleDir in examplesRoot.GetDirectories().Skip(0))
            //  var exampleDir = new DirectoryInfo(@"..\..\examples\bsbm");
            {
                Console.WriteLine("example: " + exampleDir.Name);
                //if (exampleDir.Name != @"federated subquery"
                //    //&& rqQueryFile.FullName != @"C:\Users\Admin\Source\Repos\SparqlWpf\UnitTestDotnetrdf_test\examples\insert where\query2.rq"
                //  ) continue;
                //var nameGraphsDir = new DirectoryInfo(Path.Combine(exampleDir.FullName, "named graphs"));
                //if (nameGraphsDir.Exists) continue;
                foreach (var ttlDatabase in exampleDir.GetFiles("*.ttl"))
                {
                    var store = new Store(exampleDir.FullName + "/tmp");
                    store.ClearAll();
                    //using (StreamReader reader = new StreamReader(ttlDatabase.FullName))
                    store.ReloadFrom(ttlDatabase.FullName);
                    //  store.Start();
                    var nameGraphsDir = new DirectoryInfo(Path.Combine(exampleDir.FullName, "named graphs"));
                    if (nameGraphsDir.Exists)
                    {
                        foreach (var namedGraphFile in nameGraphsDir.GetFiles())
                        {
                            IGraph graph;
                            using (StreamReader reader = new StreamReader(namedGraphFile.FullName))
                            {
                                var readLine = reader.ReadLine();
                                if (readLine == null)
                                {
                                    continue;
                                }
                                var headComment = readLine.Trim();
                                if (!headComment.StartsWith("#"))
                                {
                                    continue;
                                }
                                headComment = headComment.Substring(1);
                                //Uri uri;
                                //if (!Uri.TryCreate(headComment, UriKind.Absolute, out uri)) continue;Prologue.SplitUri(uri.AbsoluteUri).FullName
                                graph = store.NamedGraphs.CreateGraph(headComment);
                            }
                            graph.FromTurtle(namedGraphFile.FullName);
                        }
                    }

                    foreach (var rqQueryFile in exampleDir.GetFiles("*.rq"))
                    {
                        Console.WriteLine("query file: " + rqQueryFile);
                        var             outputFile      = rqQueryFile.FullName + "expected results.xml";
                        SparqlResultSet sparqlResultSet = null;
                        //  try
                        var query = rqQueryFile.OpenText().ReadToEnd();

                        SparqlQuery.SparqlClasses.Query.SparqlQuery sparqlQuery = null;
                        {
                            //Perfomance.ComputeTime(() =>
                            {
                                sparqlQuery = SparqlQueryParser.Parse(store, query);
                            } //, exampleDir.Name+" "+rqQueryFile.Name+" parse ", true);

                            if (sparqlQuery != null)
                            // Perfomance.ComputeTime(() =>
                            {
                                sparqlResultSet = sparqlQuery.Run();
                                File.WriteAllText(outputFile, sparqlResultSet.ToXml().ToString());
                            } //, exampleDir.Name + " " + rqQueryFile.Name + " run ", true);
                              //var exprectedResults= SparqlResultSet.FromXml(XElement.Load(), )
                            Assert.AreEqual(true, true, rqQueryFile.Name);
                            //File.ReadAllText(rqQueryFile.FullName + " expected results.txt"),
                            //      File.ReadAllText(outputFile));
                        }
                        //  catch (Exception e)
                        {
                            // Assert.(e.Message);
                        }
                    }
                }
            }
        }