Skip to content
  • Eric Wong's avatar
    528ff1b9
    socket: avoid arg parsing in rsock_s_recvfrom_nonblock · 528ff1b9
    Eric Wong authored
    * ext/socket/init.c (rsock_s_recvfrom_nonblock):
      avoid arg parsing with C API
      [ruby-core:71439] [Feature #11339]
    * ext/socket/basicsocket.c (bsock_recv_nonblock):
      adjust for above change, make private
    * ext/socket/socket.c (sock_recvfrom_nonblock): ditto
    * ext/socket/udpsocket.c (udp_recvfrom_nonblock): ditto
    * ext/socket/lib/socket.rb (BasicSocket#recv_nonblock):
      new wrapper for private method, move RDoc
      (Socket#recvfrom_nonblock): ditto
      (UDPSocket#recvfrom_nonblock): ditto
    
    Note, not adding bm_recv_nonblock.rb to benchmark/ directory
    since it is non-portable.  It is only in this commit message.
    
    Benchmark results + code
    target 0: a (ruby 2.3.0dev (2015-11-12 trunk 52540) [x86_64-linux])
    target 1: b (ruby 2.3.0dev (2015-11-12 avoid-kwarg-capi 52540) [x86_64-linux]
    
    -----------------------------------------------------------
    recv_nonblock
    
    require 'socket'
    nr = 1000000
    msg = 'hello world'
    buf = ''
    size = msg.bytesize
    UNIXSocket.pair(:SEQPACKET) do |a, b|
      nr.times do
        a.sendmsg(msg)
        b.recv_nonblock(size, 0, buf, exception: false)
      end
    end
    
    -----------------------------------------------------------
    raw data:
    
    [["recv_nonblock",
      [[1.83511221408844,
        1.8703329525887966,
        1.8448856547474861,
        1.859263762831688,
        1.8331583738327026],
       [1.5637447573244572,
        1.4062932096421719,
        1.4247371144592762,
        1.4108827747404575,
        1.4802536629140377]]]]
    
    Elapsed time: 16.530452496 (sec)
    -----------------------------------------------------------
    benchmark results:
    minimum results in each 5 measurements.
    Execution time (sec)
    name          a       b
    recv_nonblock   1.833   1.406
    
    Speedup ratio: compare with the result of `a' (greater is better)
    name          b
    recv_nonblock   1.304
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    528ff1b9
    socket: avoid arg parsing in rsock_s_recvfrom_nonblock
    Eric Wong authored
    * ext/socket/init.c (rsock_s_recvfrom_nonblock):
      avoid arg parsing with C API
      [ruby-core:71439] [Feature #11339]
    * ext/socket/basicsocket.c (bsock_recv_nonblock):
      adjust for above change, make private
    * ext/socket/socket.c (sock_recvfrom_nonblock): ditto
    * ext/socket/udpsocket.c (udp_recvfrom_nonblock): ditto
    * ext/socket/lib/socket.rb (BasicSocket#recv_nonblock):
      new wrapper for private method, move RDoc
      (Socket#recvfrom_nonblock): ditto
      (UDPSocket#recvfrom_nonblock): ditto
    
    Note, not adding bm_recv_nonblock.rb to benchmark/ directory
    since it is non-portable.  It is only in this commit message.
    
    Benchmark results + code
    target 0: a (ruby 2.3.0dev (2015-11-12 trunk 52540) [x86_64-linux])
    target 1: b (ruby 2.3.0dev (2015-11-12 avoid-kwarg-capi 52540) [x86_64-linux]
    
    -----------------------------------------------------------
    recv_nonblock
    
    require 'socket'
    nr = 1000000
    msg = 'hello world'
    buf = ''
    size = msg.bytesize
    UNIXSocket.pair(:SEQPACKET) do |a, b|
      nr.times do
        a.sendmsg(msg)
        b.recv_nonblock(size, 0, buf, exception: false)
      end
    end
    
    -----------------------------------------------------------
    raw data:
    
    [["recv_nonblock",
      [[1.83511221408844,
        1.8703329525887966,
        1.8448856547474861,
        1.859263762831688,
        1.8331583738327026],
       [1.5637447573244572,
        1.4062932096421719,
        1.4247371144592762,
        1.4108827747404575,
        1.4802536629140377]]]]
    
    Elapsed time: 16.530452496 (sec)
    -----------------------------------------------------------
    benchmark results:
    minimum results in each 5 measurements.
    Execution time (sec)
    name          a       b
    recv_nonblock   1.833   1.406
    
    Speedup ratio: compare with the result of `a' (greater is better)
    name          b
    recv_nonblock   1.304
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Loading