Set.insert vs array << x unless array.include?(x)

Re: Set.insert vs array << x unless array.include?(x)

Postby TIG » Mon Feb 08, 2010 9:40 pm

....or make all of your Point3d's into arrays so they will sort!/uniq! etc as arrays...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Set.insert vs array << x unless array.include?(x)

Postby thomthom » Mon Feb 08, 2010 10:29 pm

TIG wrote:....or make all of your Point3d's into arrays so they will sort!/uniq! etc as arrays...

But is the overhead of converting the Point3d's into arrays and uniq! faster than using a Set?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Set.insert vs array << x unless array.include?(x)

Postby TIG » Mon Feb 08, 2010 11:31 pm

Who knows ?
Time for you to do another test... ;)
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Set.insert vs array << x unless array.include?(x)

Postby honoluludesktop » Wed Feb 02, 2011 3:34 am

I probably don't know what I am doing, but I ran the following test, and obtained the attached results. I typically use array.push variable, and don't understand the situations when the other examples might be used. Btw, when I applied the other forms to my app, it failed in ways that leave me to believe that those forms are data sensitive. Can anyone explaine to a Ruby beginner what's up?

Code: Select all
t=Time.now
a=[]
100000.times do r=rand(10000)
  a<<r
end
a.uniq!
puts Time.now-t
0.125

Code: Select all
t=Time.now
a=[]
100000.times do r=rand(10000)
  a.push r
end
a.uniq!
puts Time.now-t
0.141

Code: Select all
t=Time.now
a=[]
100000.times do r=rand(10000)
  a.push r
end
puts Time.now-t
0.094

Code: Select all
t=Time.now
a=[]
100000.times do r=rand(10000)
  a<<r
end
puts Time.now-t
0.093
0
User avatar
honoluludesktop 
In Remembrance
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

cron

Who is online

Users browsing this forum: No registered users and 5 guests

Visit our sponsors: