summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2024-08-31 18:49:12 +0900
committernagachika <nagachika@ruby-lang.org>2024-08-31 18:49:12 +0900
commitbec6da392d26677194160cb4875f1bc491db27f5 (patch)
tree993e6cb69244f7306701b75d7e2aa85686e7aa99
parent7c2cdca7f250d0b270df585f69f275f72c415348 (diff)
merge revision(s) 533423ebe46ebfe3005198c12aa0d2c899c695ea:
core_assertions.rb: Prefer CPU time clocks To prevent influence from other processes.
-rw-r--r--tool/lib/core_assertions.rb22
-rw-r--r--version.h2
2 files changed, 21 insertions, 3 deletions
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 81faac1e4b..7625412e67 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -738,18 +738,36 @@ eom
end
alias all_assertions_foreach assert_all_assertions_foreach
+ %w[
+ CLOCK_THREAD_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID
+ CLOCK_MONOTONIC
+ ].find do |clk|
+ if Process.const_defined?(clk)
+ clk = clk.to_sym
+ begin
+ Process.clock_gettime(clk)
+ rescue
+ # Constants may be defined but not implemented, e.g., mingw.
+ else
+ PERFORMANCE_CLOCK = clk
+ end
+ end
+ end
+
# Expect +seq+ to respond to +first+ and +each+ methods, e.g.,
# Array, Range, Enumerator::ArithmeticSequence and other
# Enumerable-s, and each elements should be size factors.
#
# :yield: each elements of +seq+.
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
+ pend "No PERFORMANCE_CLOCK found" unless defined?(PERFORMANCE_CLOCK)
+
# Timeout testing generally doesn't work when RJIT compilation happens.
rjit_enabled = defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
measure = proc do |arg, message|
- st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ st = Process.clock_gettime(PERFORMANCE_CLOCK)
yield(*arg)
- t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
+ t = (Process.clock_gettime(PERFORMANCE_CLOCK) - st)
assert_operator 0, :<=, t, message unless rjit_enabled
t
end
diff --git a/version.h b/version.h
index 6a5a3d4be0..90446b31f0 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 5
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 217
+#define RUBY_PATCHLEVEL 218
#include "ruby/version.h"
#include "ruby/internal/abi.h"