Mercurial > pub > Jint1
comparison Jint.Runtime/Main.cs @ 0:e113095f1de0
initial commit, proof of concept
author | cin |
---|---|
date | Wed, 23 Oct 2013 13:24:57 +0400 |
parents | |
children | 4aed85a1f558 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e113095f1de0 |
---|---|
1 using System; | |
2 using Jint.Runtime.VM.OpCodes; | |
3 | |
4 namespace Jint.Runtime | |
5 { | |
6 using VM; | |
7 using System.IO; | |
8 class MainClass | |
9 { | |
10 public static void Main(string[] args) | |
11 { | |
12 var runtime = new RuntimeContext (); | |
13 | |
14 var frame = new Frame (3,runtime); | |
15 | |
16 frame.Set (0, 0); | |
17 frame.Set (1, 1); | |
18 | |
19 var op = new Add (0,1,0); | |
20 | |
21 var t = Environment.TickCount; | |
22 | |
23 for(int i=0; i < 10000000; i++) | |
24 op.Invoke (frame); | |
25 | |
26 var res = frame.Get<int> (0); | |
27 | |
28 Console.WriteLine ("got: {0}, int {1} ms", res, Environment.TickCount - t ); | |
29 | |
30 t = Environment.TickCount; | |
31 | |
32 object count = 0, inc = 1; | |
33 for (int i=0; i< 10000000; i++) | |
34 count = OpAdd(count,inc); | |
35 | |
36 Console.WriteLine ("reference results: {0}, int {1} ms", count, Environment.TickCount - t ); | |
37 } | |
38 | |
39 public static object OpAdd(object arg1, object arg2) { | |
40 if (arg1.GetType () == arg2.GetType ()) { | |
41 return OpAddIntegers(arg1,arg2); | |
42 } | |
43 throw new Exception (); | |
44 } | |
45 | |
46 public static object OpAddIntegers(object arg1, object arg2) { | |
47 return (int)arg1 + (int)arg2; | |
48 } | |
49 } | |
50 } |