Project

General

Profile

Bug #18692

Updated by jablin (Johannes Abt) over 3 years ago

 
     $ `$ time ruby26 --disable=gems -r set -e 's = Set.new(); 1.upto(10_000).each { |n| s += [n] }' 

     
 real      0m1.346s 
     
 user      0m1.290s 
     
 sys       0m0.055s 


 Three 
 ` 

 Tree times the input size: 

     $ 

 `$ time ruby26 --disable=gems -r set -e 's = Set.new(); 1.upto(30_000).each { |n| s += [n] }' 

     

 real      0m13.099s 
     
 user      0m12.443s 
     
 sys       0m0.642s 


 Three 
 ` 

 Tree times the input size is 9 to 10 times the runtime! 


 For comparsion, using the `<<` operator instead of `+=`: 


     $ 


 `$ time ruby26 --disable=gems -r set -e 's = Set.new(); 1.upto(5_000_000).each { |n| s << n }' 

     

 real      0m1.472s 
     
 user      0m1.290s 
     
 sys       0m0.180s 

 
 ` 

Back