J
James Edward Gray II
James:
I'm going to have to respectfully disagree.
Well, I'm pretty darn sure you are in the minority on that one:
http://www.google.com/search?q="premature+optimization"
James Edward Gray II
James:
I'm going to have to respectfully disagree.
James:
This code doesn't work on my Mac. I do have a version that uses the
file block and each/foreach above, but I'm suspecting that when the
string becomes an array after the split something's breaking down as I
get words of all sizes out???
J> Something is fishy there, for it works just fine on my own Mac:
Try it with
J> Neo:~/Desktop$ cat wordlist
J> one
J> two
J> three
J> 0123456789
01234567890123456789
Well, I'm pretty darn sure you are in the minority on that one:![]()
Additionally, the "no premature optimization ideal" is often taken
a little too far. I intentionally call it an "ideal". I work on
video games. A good portion of our job is optimization. If we
didn't do *some* premature optimization, we'd be in bad shape.
James:James said:Well, I'm pretty darn sure you are in the minority on that one:
http://www.google.com/search?q="premature+optimization"
James Edward Gray II
Benjohn said:!?How on earth does that work? Every time I think I've sort of got
the hang of regexp, they spring something new on me.
I was also going to ask why everyone was doing "split( // )" instead of
"split( '' )"?
- oooh, coffee's ready...
Cheers,
Benjohn
Alan said:I just wrote my first Ruby script. I'm an experienced C and perl
programmer, so please, if it looks too much like these languages and not
Ruby, let me know. I've got a 100K word list (Linux dictionary) on my
Mac and am opening it then looking for any words that are exactly 10
letters long with no letters repeating ('profligate\n') == 11 is a
match. After I wrote my first version I did some playing. I first saw
that the array class mixed in enumerable and that I could use the to_a
call from there, but a quick check using -r profile showed that my
original call to split was a much quicker way to convert from a string
to an array. I then tried putting the File.open in a block and found
that this was much slower, even if I subtract out the time for the open,
which I assume is an error in how the profile is counting total time.
Here's the faster version:
f = File.open("./words")
begin
while f.gets
if $_.length == 11
ar = $_.split(//)
if ar.uniq! == nil
print "#{ar.to_s}"
end
end
end
rescue EOFError
f.close
end
And here's the slower block version:
File.open("./words") { |f|
while f.gets
if $_.length == 11
ar = $_.split(//)
if ar.uniq! == nil
print "#{ar.to_s}"
end
end
end
}
Well, I'm pretty darn sure you are in the minority on that one:
http://www.google.com/search?q="premature+optimization"
Alan Burch said:Others:
Any input as to why it runs slower inside the file block? Have I
overlooked something simple?
Thanks David and others who stated what I wanted to say better than IThis isn't an argument in favor of premature optimization; rather, I'm
suggesting that having and using some rough-cut knowledge of execution
speed (as between, say, split and unpack, or something like that)
isn't prematureNor is it optimization; it's really melioration.
David
This isn't an argument in favor of premature optimization; rather, I'm
suggesting that having and using some rough-cut knowledge of execution
speed (as between, say, split and unpack, or something like that)
isn't prematureNor is it optimization; it's really melioration.
File.open( "./words" ).readlines.each do |line|
print line if line.length == 11 and line.split.uniq
end
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.