summaryrefslogtreecommitdiff
path: root/benchmark/so_object.rb
blob: 131f44624cae3b1c99176b0d18c8b74a0928d641 (plain)
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
52
53
54
55
56
#!/usr/bin/ruby
# -*- Ruby -*-
# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Aristarkh Zagorodnikov

class Toggle
    def initialize(start_state)
        @bool = start_state
    end

    def value
        @bool
    end

    def activate
        @bool = !@bool
        self
    end
end

class NthToggle < Toggle
    def initialize(start_state, max_counter)
        super start_state
        @count_max = max_counter
        @counter = 0
    end

    def activate
        @counter += 1
        if @counter >= @count_max
            @bool = !@bool
            @counter = 0
        end
        self
    end
end

n = 1500000 # (ARGV.shift || 1).to_i

toggle = Toggle.new 1
5.times do
    toggle.activate.value ? 'true' : 'false'
end
n.times do
    toggle = Toggle.new 1
end

ntoggle = NthToggle.new 1, 3
8.times do
    ntoggle.activate.value ? 'true' : 'false'
end
n.times do
    ntoggle = NthToggle.new 1, 3
end

td>Nobuyoshi Nakada If `posix_openpt` is available, also `ptsname` should be available. 2024-04-11[pty] Support `ptsname_r` of glibcNobuyoshi Nakada Although glibc `ptsname_r` man page mentions Tru64 and HP-UX, this function appears to be declared obsolete on both. 2024-04-09[pty] Split `chfunc` into functions in stepsNobuyoshi Nakada - start a new session - obtain the new controlling terminal - drop privileges - finally, `exec` 2024-04-07Fix a typo, missing `P` in `SETPGRP_VOID`Nobuyoshi Nakada 2024-04-04Revert "hijack SIGCHLD handler for internal use"Nobuyoshi Nakada This reverts commit 054a412d540e7ed2de63d68da753f585ea6616c3. SIGCHLD `waidpid`, `waitpid_lock` and related code, have been removed at ruby/ruby#7527. 2023-12-18[DOC] Show `PTY.getpty` as an alias of `PTY.spawn`Nobuyoshi Nakada `:nodoc:` directive does not work at method definition in C, and must be at the implementation function. That is, there is no way to make one method visible and another method sharing the implementation invisible at the same time. 2023-06-01Hide the usage of `rb_io_t` where possible. (#7880)Samuel Williams This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility. Notes: Merged-By: ioquatix <samuel@codeotaku.com> 2023-06-01Revert "Hide most of the implementation of `struct rb_io`. (#6511)"NARUSE, Yui This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2. fix [Bug #19704] https://bugs.ruby-lang.org/issues/19704 This breaks compatibility for extension libraries. Such changes need a discussion. 2023-05-30Hide most of the implementation of `struct rb_io`. (#6511)Samuel Williams * Add rb_io_path and rb_io_open_descriptor. * Use rb_io_open_descriptor to create PTY objects * Rename FMODE_PREP -> FMODE_EXTERNAL and expose it FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but FMODE_EXTERNAL is clearer about what the file descriptor represents and aligns with language in the IO::Buffer module. * Ensure that rb_io_open_descriptor closes the FD if it fails If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be responsible for closing your file, eventually, if you pass it to rb_io_open_descriptor, even if it raises an exception. * Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P * Expose `rb_io_closed_p`. * Add `rb_io_mode` to get IO mode. --------- Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com> Notes: Merged-By: ioquatix <samuel@codeotaku.com> 2023-02-28Update the depend filesMatt Valentine-House Notes: Merged: https://github.com/ruby/ruby/pull/7310 2023-02-27Remove intern/gc.h from Make depsMatt Valentine-House Notes: Merged: https://github.com/ruby/ruby/pull/7330 2023-02-08Extract include/ruby/internal/attr/packed_struct.hNobuyoshi Nakada Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the macros bellow: * `RBIMPL_ATTR_PACKED_STRUCT_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_END` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END` Notes: Merged: https://github.com/ruby/ruby/pull/7268 2022-11-10Transition shape when object's capacity changesJemma Issroff This commit adds a `capacity` field to shapes, and adds shape transitions whenever an object's capacity changes. Objects which are allocated out of a bigger size pool will also make a transition from the root shape to the shape with the correct capacity for their size pool when they are allocated. This commit will allow us to remove numiv from objects completely, and will also mean we can guarantee that if two objects share shapes, their IVs are in the same positions (an embedded and extended object cannot share shapes). This will enable us to implement ivar sets in YJIT using object shapes. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/6699