Mercurial > pub > Jint1
comparison Jint.Runtime/Main.cs @ 2:4aed85a1f558
implemented simple vm2
author | cin |
---|---|
date | Fri, 25 Oct 2013 15:52:16 +0400 |
parents | e113095f1de0 |
children | aced2ae9957f |
comparison
equal
deleted
inserted
replaced
1:033ebe7432d5 | 2:4aed85a1f558 |
---|---|
32 object count = 0, inc = 1; | 32 object count = 0, inc = 1; |
33 for (int i=0; i< 10000000; i++) | 33 for (int i=0; i< 10000000; i++) |
34 count = OpAdd(count,inc); | 34 count = OpAdd(count,inc); |
35 | 35 |
36 Console.WriteLine ("reference results: {0}, int {1} ms", count, Environment.TickCount - t ); | 36 Console.WriteLine ("reference results: {0}, int {1} ms", count, Environment.TickCount - t ); |
37 | |
38 var code = new VM2.Instruction[10000000]; | |
39 | |
40 for (int i = 0; i < code.Length; i++) | |
41 code[i] = new VM2.Instruction(){ code = VM2.OpCodes.Codes.Add, dest = 0, args = new int[] {0,1} }; | |
42 var machine = new VM2.Machine (); | |
43 | |
44 t = Environment.TickCount; | |
45 | |
46 machine.InitFrame (new object[] { 0, 1 }); | |
47 machine.Execute (code); | |
48 | |
49 Console.WriteLine ("vm2: {0}, int {1} ms", machine.Get(0), Environment.TickCount - t ); | |
37 } | 50 } |
38 | 51 |
39 public static object OpAdd(object arg1, object arg2) { | 52 public static object OpAdd(object arg1, object arg2) { |
40 if (arg1.GetType () == arg2.GetType ()) { | 53 if (arg1.GetType () == arg2.GetType ()) { |
41 return OpAddIntegers(arg1,arg2); | 54 return OpAddIntegers(arg1,arg2); |