protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test) { var times = new List <long>(); try { //Warmup run so we don't get hit by IronJS assembly JIT overhead ctx.ExecuteFile(test); for (int i = 0; i < Runs; i++) { // Collect all garbage between runs GC.Collect(2, GCCollectionMode.Forced); // Run and time var sw = Stopwatch.StartNew(); ctx.ExecuteFile(test); sw.Stop(); times.Add(sw.ElapsedMilliseconds); } } catch (Exception ex) { return(new TestResult { Error = ex.GetBaseException().Message, Tag = Tuple.Create(test, Enumerable.Repeat(-1L, Runs).ToArray()) }); } return(new TestResult { Score = GetScore(times), Tag = Tuple.Create(test, times.ToArray()) }); }
/** * This is badly named - really it sets up the * global context and then executes the file given * on within that context. */ public void ReadJsFile(string in_filename) { commonjs.SetRequireStack(in_filename); // string pathpart = Path.GetDirectoryName( in_filename ); // path = Directory.GetCurrentDirectory() + pathpart; // log.Trace( "path of js file: " + path ); var emit = Utils.createHostFunction <Action <IronJS.BoxedValue> >( ctx.Environment, (obj) => { Console.WriteLine(IronJS.TypeConverter.ToString(obj)); } ); ctx.SetGlobal <IronJS.FunctionObject>("puts", emit); var require = Utils.createHostFunction <Func <string, IronJS.CommonObject> >( ctx.Environment, (obj) => { return(Require(obj)); } ); ctx.SetGlobal <IronJS.FunctionObject>("require", require); // Forms the `net" namespace ctx.SetGlobal <IronJS.CommonObject>("net", netObj); // Forms the `http" namespace // TODO: re-add after httpserver.cs is converted to IJS 0.2 // ctx.SetGlobal<IronJS.CommonObject>( "http", httpObj ); ctx.ExecuteFile(in_filename); }
protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test) { var errors = new StringBuilder(); Action <string> appendError = err => { if (errors.Length > 0) { errors.AppendLine(); } errors.Append(err); }; var score = string.Empty; Action <string, string> notifyResult = (name, result) => { }; Action <string, string> notifyError = (name, error) => appendError(name + ": " + error); Action <string> notifyScore = s => score = s; ctx.SetGlobal("NotifyResult", IronJS.Native.Utils.CreateFunction(ctx.Environment, 2, notifyResult)); ctx.SetGlobal("NotifyError", IronJS.Native.Utils.CreateFunction(ctx.Environment, 2, notifyError)); ctx.SetGlobal("NotifyScore", IronJS.Native.Utils.CreateFunction(ctx.Environment, 1, notifyScore)); try { ctx.ExecuteFile(test); ctx.Execute(@"BenchmarkSuite.RunSuites({ NotifyResult: NotifyResult, NotifyError: NotifyError, NotifyScore: NotifyScore });"); } catch (Exception ex) { appendError("Exception: " + ex.GetBaseException().Message); } if (errors.Length > 0) { return(new TestResult { Error = errors.ToString() }); } else { return(new TestResult { Score = score }); } }
public void SomeTest() { Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); var context = new IronJS.Hosting.CSharp.Context(); context.ExecuteFile(@"c:\temp\test.js"); var span = new TimeSpan(0, 0, 42,37); var add = context.Globals.GetT<FunctionObject>("calculate"); var age = 43; var distance = 10; var gender = "M"; var value = Convert.ToDouble(add.Call(context.Globals, gender, Convert.ToDouble(age), Convert.ToDouble(distance), span.TotalSeconds).Unbox<object>()); Console.WriteLine(value); }
protected virtual TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test) { Stopwatch sw; try { sw = Stopwatch.StartNew(); ctx.ExecuteFile(test); sw.Stop(); } catch (Exception ex) { return(new TestResult { Error = ex.GetBaseException().Message }); } return(new TestResult { Score = sw.ElapsedMilliseconds + "ms" }); }