7
7
import json
8
8
import os
9
9
import re
10
- import shutil
11
10
import sys
12
- import tempfile
13
- from subprocess import Popen
11
+ import subprocess
14
12
15
- __rootpath__ = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
13
+ __scriptdir__ = os .path .dirname (os .path .abspath (__file__ ))
14
+ __testdir__ = os .path .dirname (os .path .dirname (__file__ ))
15
+ __rootpath__ = os .path .dirname (__testdir__ )
16
+ print (__rootpath__ )
16
17
sys .path .insert (0 , __rootpath__ )
18
+ sys .path .insert (0 , __testdir__ )
17
19
18
- from tools .shared import WINDOWS , CLANG_CXX , EMCC , PIPE
20
+ from tools .shared import WINDOWS , CLANG_CXX , EMCC
19
21
from tools .shared import run_process
20
22
from tools .config import V8_ENGINE
21
23
from common import EMRUN , test_file
22
24
import clang_native
23
25
24
- temp_dir = tempfile .mkdtemp ()
25
-
26
26
# System info
27
- system_info = Popen ([EMRUN , '--system_info' ], stdout = PIPE , stderr = PIPE ). communicate ( )
27
+ system_info = subprocess . check_output ([EMRUN , '--system_info' ], stderr = subprocess . STDOUT , text = True )
28
28
29
29
# Native info
30
- native_info = Popen (['clang' , '-v' ], stdout = PIPE , stderr = PIPE ). communicate ( )
30
+ native_info = subprocess . check_output (['clang' , '-v' ], stderr = subprocess . STDOUT , text = True )
31
31
32
32
# Emscripten info
33
- emscripten_info = Popen ([EMCC , '-v' ], stdout = PIPE , stderr = PIPE ). communicate ( )
33
+ emscripten_info = subprocess . check_output ([EMCC , '-v' ], stderr = subprocess . STDOUT , text = True )
34
34
35
35
36
36
def run_benchmark (benchmark_file , results_file , build_args ):
37
+ out_dir = os .path .join (__rootpath__ , 'out' )
38
+ results_file = os .path .join (out_dir , results_file )
37
39
# Run native build
38
- out_file = os .path .join (temp_dir , 'benchmark_sse_native' )
40
+ out_file = os .path .join (out_dir , 'benchmark_sse_native' )
39
41
if WINDOWS :
40
42
out_file += '.exe'
41
43
cmd = [CLANG_CXX ] + clang_native .get_clang_native_args () + [benchmark_file , '-O3' , '-o' , out_file ]
42
44
print ('Building native version of the benchmark:' )
43
45
print (' ' .join (cmd ))
44
46
run_process (cmd , env = clang_native .get_clang_native_env ())
45
47
46
- native_results = Popen ([ out_file ], stdout = PIPE , stderr = PIPE ). communicate ( )
47
- print (native_results [ 0 ] )
48
+ native_results = subprocess . check_output ( out_file )
49
+ print (' native_results' , native_results )
48
50
49
51
# Run emscripten build
50
- out_file = os .path .join (temp_dir , 'benchmark_sse_html.js' )
51
- cmd = [EMCC , benchmark_file , '-O3' , '-sTOTAL_MEMORY=536870912' , '-o' , out_file ] + build_args
52
+ out_file = os .path .join (out_dir , 'benchmark_sse_html.js' )
53
+ cmd = [EMCC , benchmark_file , '-sENVIRONMENT=web,shell,node' , '-msimd128' , '- O3' , '-sTOTAL_MEMORY=536870912' , '-o' , out_file ] + build_args
52
54
print ('Building Emscripten version of the benchmark:' )
53
55
print (' ' .join (cmd ))
54
56
run_process (cmd )
55
57
56
- cmd = V8_ENGINE + ['--experimental-wasm-simd' , os .path .basename (out_file )]
58
+ cmd = V8_ENGINE + [os .path .basename (out_file )]
57
59
print (' ' .join (cmd ))
58
- old_dir = os .getcwd ()
59
- os .chdir (os .path .dirname (out_file ))
60
- wasm_results = Popen (cmd , stdout = PIPE , stderr = PIPE ).communicate ()
61
- os .chdir (old_dir )
62
-
63
- if not wasm_results :
64
- raise Exception ('Unable to run benchmark in V8!' )
60
+ wasm_results = subprocess .check_output (cmd , cwd = out_dir , text = True )
65
61
66
- if not wasm_results [0 ].strip ():
67
- print (wasm_results [1 ])
68
- sys .exit (1 )
69
-
70
- print (wasm_results [0 ])
62
+ print ('wasm_results' , wasm_results )
71
63
72
64
def strip_comments (text ):
73
- return re .sub ('//.*?\n |/\*.*?\*/' , '' , text , re .S ) # noqa
65
+ return re .sub (r '//.*?\n|/\*.*?\*/' , '' , text , flags = re .S ) # noqa
74
66
75
- benchmark_results = strip_comments (wasm_results [0 ])
67
+ benchmark_results = strip_comments (wasm_results )
68
+ print ('stripped' , benchmark_results )
76
69
77
70
# Strip out unwanted print output.
78
71
benchmark_results = benchmark_results [benchmark_results .find ('{' ):].strip ()
@@ -81,9 +74,7 @@ def strip_comments(text):
81
74
82
75
print (benchmark_results )
83
76
84
- shutil .rmtree (temp_dir )
85
-
86
- native_results = json .loads (native_results [0 ])
77
+ native_results = json .loads (native_results )
87
78
benchmark_results = benchmark_results [benchmark_results .index ('{' ):benchmark_results .rindex ('}' ) + 1 ]
88
79
wasm_results = json .loads (benchmark_results )
89
80
@@ -94,11 +85,11 @@ def strip_comments(text):
94
85
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
95
86
<script src="https://code.highcharts.com/highcharts.js"></script>
96
87
<script src="https://code.highcharts.com/modules/exporting.js"></script><b>System Info:</b><br/>
97
- ''' + system_info [ 0 ] .replace ('\n ' , '<br/>' ) + '''
88
+ ''' + system_info .replace ('\n ' , '<br/>' ) + '''
98
89
<b>Native Clang Compiler:</b><br/>
99
- ''' + native_info [ 1 ] .replace ('\n ' , '<br/>' ) + '''
90
+ ''' + native_info .replace ('\n ' , '<br/>' ) + '''
100
91
<b>Emscripten Compiler:</b><br/>
101
- ''' + emscripten_info [ 0 ] .replace ('\n ' , '<br/>' )
92
+ ''' + emscripten_info .replace ('\n ' , '<br/>' )
102
93
103
94
charts_native = {}
104
95
charts_html = {}
@@ -294,12 +285,12 @@ def format_comparison(a, b):
294
285
if __name__ == '__main__' :
295
286
suite = sys .argv [1 ].lower () if len (sys .argv ) == 2 else None
296
287
if suite in ['sse' , 'sse1' ]:
297
- run_benchmark (test_file ('sse /benchmark_sse1.cpp' ), 'results_sse1.html' , ['-msse' ])
288
+ run_benchmark (test_file ('benchmark /benchmark_sse1.cpp' ), 'results_sse1.html' , ['-msse' ])
298
289
elif suite == 'sse2' :
299
- run_benchmark (test_file ('sse /benchmark_sse2.cpp' ), 'results_sse2.html' , ['-msse2' ])
290
+ run_benchmark (test_file ('benchmark /benchmark_sse2.cpp' ), 'results_sse2.html' , ['-msse2' ])
300
291
elif suite == 'sse3' :
301
- run_benchmark (test_file ('sse /benchmark_sse3.cpp' ), 'results_sse3.html' , ['-msse3' ])
292
+ run_benchmark (test_file ('benchmark /benchmark_sse3.cpp' ), 'results_sse3.html' , ['-msse3' ])
302
293
elif suite == 'ssse3' :
303
- run_benchmark (test_file ('sse /benchmark_ssse3.cpp' ), 'results_ssse3.html' , ['-mssse3' ])
294
+ run_benchmark (test_file ('benchmark /benchmark_ssse3.cpp' ), 'results_ssse3.html' , ['-mssse3' ])
304
295
else :
305
- raise Exception ('Usage: python test/benchmark_sse.py sse1|sse2|sse3' )
296
+ raise Exception ('Usage: python test/benchmark/ benchmark_sse.py sse1|sse2|sse3' )
0 commit comments