Project

General

Profile

Feature #11242

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

--- 
 Note, this relies on [Feature #11229] 

 This reduces GC overhead and makes the API more consistent 
 with `IO#read` IO#read and `IO#read_nonblock`. IO#read_nonblock. 

 Benchmark results: 

         | 

              user       user    |     system    |             total |                  real 
 --------|----------:|----------:|---------:|-----------: 
 alloc      0.130000     | 0.130000    | 0.280000    |     0.410000 |( (    0.420656) 
 extbuf    |     0.100000    |     0.220000    |     0.320000 |( (    0.318708) 

 ~~~ruby 
 ------------------------8<----------------------- 
 require 'socket' 
 require 'benchmark' 
 nr = 100000 
 msg = ' ' * 16384 
 size = msg.bytesize 
 buf = ' ' * size 
 UNIXSocket.pair(:DGRAM) do |a, b| 
   Benchmark.bmbm do |x| 
     x.report('alloc') do 
       nr.times do 
         b.send(msg, 0) 
         a.recv(size, 0) 
       end 
     end 

     x.report('extbuf') do 
       nr.times do 
         b.send(msg, 0) 
         a.recv(size, 0, buf) 
       end 
     end 
   end 
 end 
 ~~~ --- 

Back