// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Net; using System.Threading; using System.Text.RegularExpressions; namespace E { public class TestClass { private const int NGET = 10000; private static int getprthread; private static void TestThread() { for(int i = 0; i < getprthread; i++) { WebRequest wr = WebRequest.Create("http://localhost:8080/PSPExamples/test.psp"); //WebRequest wr = WebRequest.Create("http://localhost:8080/test/test.jsp"); string html = (new StreamReader(wr.GetResponse().GetResponseStream())).ReadToEnd(); if(html.Length < 20) { Console.WriteLine("Error"); } } } public static void Test(int nthreads) { getprthread = NGET / nthreads; Thread[] thr = new Thread[nthreads]; for(int i = 0; i < thr.Length; i++) { thr[i] = new Thread(new ThreadStart(TestThread)); } long t1 = DateTime.Now.Ticks; for(int i = 0; i < thr.Length; i++) { thr[i].Start(); } for(int i = 0; i < thr.Length; i++) { thr[i].Join(); } long t2 = DateTime.Now.Ticks; Console.WriteLine("WebWare (" + nthreads + " threads): " + NGET / ((t2 - t1)/1000000) + " get per second"); //Console.WriteLine("Tomcat (" + nthreads + " threads): " + NGET / ((t2 - t1)/1000000) + " get per second"); } private const int REP = 3; public static void Main(string[] args) { for(int i = 0; i < REP; i++) { Test(1); Test(10); Test(100); } } } }