ruby/benchmark/string_valid_encoding_p.yml
Sampo Kuokkanen 93e977936f Define String#ascii_only? and #valid_encoding? in Ruby
Get rid of the CFUNC overhead in String#ascii_only? and #valid_encoding?. Define them as leaf Primitive.cexpr! builtins in a new string.rb, following the pattern of numeric.rb.

This makes them 1.2x-1.4x faster across the interpreter, YJIT, and
ZJIT.

Move ZJIT's cfunc annotation for String#ascii_only? to annotate_builtin!, and add one for String#valid_encoding?.

Fix CI for builtin String#ascii_only?
2026-06-24 17:17:33 -04:00

8 lines
203 B
YAML

prelude: |
utf8 = "héllo wörld 晦"
broken = "\xff\xfe".dup.force_encoding("UTF-8")
benchmark:
valid_enc_true: utf8.valid_encoding?
valid_enc_false: broken.valid_encoding?
loop_count: 20000000