-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.py
executable file
·51 lines (41 loc) · 1.82 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import json
import subprocess
import sys
import time
class Client:
def __init__(self, cmd, cwd):
self.p = subprocess.Popen(cmd.split(" "), stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True, cwd=cwd)
def request(self, request):
self.p.stdin.write(json.dumps(request) + "\n")
return json.loads(self.p.stdout.readline())
def compile(self, code, stdlib):
return self.request({"cmd": "compile", "code": code, "stdlibCode": stdlib, "className": "TestClass", "methodName": "testMethod" })
#python = Client("python -u InMemoryCompilers/Python/jsonrepl.py")
#for i in range(2):
# print "python = %r" % python.compile("print 'hello world %d'" % i, "")
#php = Client("php InMemoryCompilers/PHP/jsonrepl.php")
#php.compile("print 'hello world';", "")
#ruby = Client("ruby InMemoryCompilers/Ruby/jsonrepl.rb")
#print "Ruby = %r" % ruby.compile("puts 'hello world';", "")
#tsjs = Client("node InMemoryCompilers/TypeScript/jsonrepl.js")
#print "TS/JS = %r" % tsjs.compile("console.log('hello world');", "")
java = Client("java -cp target/classes:lib/* fastjavacompile.App", "InMemoryCompilers/Java")
print "java = %r" % java.compile('''
class Program {
public static void main(String[] args) {
System.out.println("hello world!");
}
}''', "")
#for i in range(2):
# print "php = %r" % php.compile("print 'hello world %d';" % i, "")
start = time.time()
for i in range(1):
java.compile('''
class Program {
public static void main(String[] args) {
System.out.println("hello %d!");
}
}''' % i, "")
elapsedMs = int((time.time() - start) * 1000)
print "done: %dms" % elapsedMs