@@ -10,6 +10,7 @@ class ArgumentParser
1010 :harness ,
1111 :harness_explicit ,
1212 :yjit_opts ,
13+ :zjit_opts ,
1314 :categories ,
1415 :name_filters ,
1516 :excludes ,
@@ -19,6 +20,7 @@ class ArgumentParser
1920 :force_pinning ,
2021 :turbo ,
2122 :skip_yjit ,
23+ :skip_zjit ,
2224 :with_pre_init ,
2325 keyword_init : true
2426 )
@@ -35,7 +37,7 @@ def parse(argv)
3537 args = default_args
3638
3739 OptionParser . new do |opts |
38- opts . on ( "-e=NAME::RUBY_PATH OPTIONS" , "ruby executable and options to be benchmarked (default: interp, yjit)" ) do |v |
40+ opts . on ( "-e=NAME::RUBY_PATH OPTIONS" , "ruby executable and options to be benchmarked (default: interp, yjit, zjit )" ) do |v |
3941 v . split ( ";" ) . each do |name_executable |
4042 name , executable = name_executable . split ( "::" , 2 )
4143 if executable . nil?
@@ -91,6 +93,10 @@ def parse(argv)
9193 args . skip_yjit = true
9294 end
9395
96+ opts . on ( "--skip-zjit" , "Don't run with zjit after interpreter" ) do
97+ args . skip_zjit = true
98+ end
99+
94100 opts . on ( "--harness=HARNESS_DIR" , "which harness to use" ) do |v |
95101 v = "harness-#{ v } " unless v . start_with? ( 'harness' )
96102 args . harness = v
@@ -124,6 +130,10 @@ def parse(argv)
124130 args . yjit_opts = str
125131 end
126132
133+ opts . on ( "--zjit-opts=OPT_STRING" , "string of command-line options to run ZJIT with (ignored if you use -e)" ) do |str |
134+ args . zjit_opts = str
135+ end
136+
127137 opts . on ( "--with_pre-init=PRE_INIT_FILE" ,
128138 "a file to require before each benchmark run, so settings can be tuned (eg. enable/disable GC compaction)" ) do |str |
129139 args . with_pre_init = str
@@ -157,9 +167,16 @@ def parse(argv)
157167
158168 # If -e is not specified, benchmark the current Ruby. Compare it with YJIT if available.
159169 if args . executables . empty?
160- if have_yjit? ( @ruby_executable ) && !args . skip_yjit
170+ use_yjit = have_yjit? ( @ruby_executable ) && !args . skip_yjit
171+ use_zjit = have_zjit? ( @ruby_executable ) && !args . skip_zjit
172+ if use_yjit || use_zjit
161173 args . executables [ "interp" ] = [ @ruby_executable ]
162- args . executables [ "yjit" ] = [ @ruby_executable , "--yjit" , *args . yjit_opts . shellsplit ]
174+ if use_yjit
175+ args . executables [ "yjit" ] = [ @ruby_executable , "--yjit" , *args . yjit_opts . shellsplit ]
176+ end
177+ if use_zjit
178+ args . executables [ "zjit" ] = [ @ruby_executable , "--zjit" , *args . zjit_opts . shellsplit ]
179+ end
163180 else
164181 args . executables [ "ruby" ] = [ @ruby_executable ]
165182 end
@@ -184,6 +201,11 @@ def have_yjit?(ruby)
184201 ruby_version . downcase . include? ( "yjit" )
185202 end
186203
204+ def have_zjit? ( ruby )
205+ ruby_version = `#{ ruby } -v --zjit 2> #{ File ::NULL } ` . strip
206+ ruby_version . downcase . include? ( "zjit" )
207+ end
208+
187209 def default_args
188210 Args . new (
189211 executables : { } ,
@@ -192,6 +214,7 @@ def default_args
192214 harness : "harness" ,
193215 harness_explicit : false ,
194216 yjit_opts : "" ,
217+ zjit_opts : "" ,
195218 categories : [ ] ,
196219 name_filters : [ ] ,
197220 excludes : [ ] ,
@@ -201,6 +224,7 @@ def default_args
201224 force_pinning : false ,
202225 turbo : false ,
203226 skip_yjit : false ,
227+ skip_zjit : true ,
204228 with_pre_init : nil ,
205229 )
206230 end
0 commit comments