private void btnTest_Click(object sender, EventArgs e)
{
using (JavascriptContext context = new JavascriptContext())
{
Stopwatch sw = new Stopwatch();
sw.Start();
int i=1000000;
while(i-- > 0)
{
context.SetParameter("ii", 1);
context.SetParameter("jj", 2);
context.SetParameter("sum", 0);
string js = string.Format(@"sum=ii+jj;");
context.Run(js);
int sum = (int)context.GetParameter("sum");
}
sw.Stop();
long useJS_Total = sw.ElapsedMilliseconds;
float useJS_Average = ((float)sw.ElapsedMilliseconds) / 1000000;
sw.Reset();
sw.Start();
i = 1000000;
while (i-- > 0)
{
int ii = 1;
int jj = 2;
int sum = 0;
sum = ii + jj;
}
sw.Stop();
long nouseJS_Total = sw.ElapsedMilliseconds;
float nouseJS_Average = ((float)sw.ElapsedMilliseconds) / 1000000;
string msg = "";
msg += string.Format("useJS_Total: {0}\r\n", useJS_Total);
msg += string.Format("useJS_Average: {0}\r\n\r\n\r\n", useJS_Average);
msg += string.Format("nouseJS_Total: {0}\r\n", nouseJS_Total);
msg += string.Format("nouseJS_Average: {0}\r\n\r\n\r\n", nouseJS_Average);
MessageBox.Show(msg);
}
}