Optimization Tips
-
It's ok. I just hoped there was a config UI for BBCode tags on the forum. Thought it was normal. The
code
tag is ok, just figured if it could be changed...I don't suppose there are forum plugins that can be installed? having the code block apply syntax highlighting would be a delight for us coders. Such as this:
http://code.google.com/p/syntaxhighlighter/
Edit: what version of phpBB does SCF run? I'm looking at this: http://www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/ from this it appear to be that it'd be a matter of setting the HTML replacement for the ruby tag to not collapse white space using CSS.
Replacement sample something like this:
<span style="white-space:pre;">{TEXT}</span>
-
I can imagine you would like that syntax highlight! I use Notepad++ and know what a difference it is!
Coen and Tavi should be spoken to about these things.
-
@adamb said:
I see a lot of SU scripts using some of the more compact iterators Ruby iterators. So they might read nice, but they're often slower than just simple for-loops.
In regard to this should one init the variables used by
for in
to speed up things? or is that not needed?Would this
` x = 0
for x in collection...
end
be faster than
for x in collection...
end`
-
no
-
I've always thought
for
usedeach
under the hood.http://blog.grayproductions.net/articles/the_evils_of_the_for_loop
for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.
With
.each
, variables are local to the block {..} -
@jim said:
I've always thought
for
usedeach
under the hood.http://blog.grayproductions.net/articles/the_evils_of_the_for_loop
for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.
If you click the method names in the Ruby API manual you get to see the sourcecode:
http://ruby-doc.org/core/classes/Array.html#M002173 -
That's showing a for loop in the c language.
-
That's what it's doing under the hood.
-
@thomthom said:
That's what it's doing under the hood.
Right, so where is the definition for the
for
function?The answer is there isn't one because
for
is not a function, but is "sugar". Thefor
loop in Ruby really uses the.each
method behind the scenes.Although, I can't recall where I learned that. The link to the blog article mentions it, though.
-
speaking of each vs for :
loop1 = [] loop2 = [] calls = ["one", "two", "three"] calls.each do |c| loop1 << Proc.new { puts c } end for c in calls loop2 << Proc.new { puts c } end loop1[1].call #=> "two" loop2[1].call #=> "three"
-
@jim said:
The
for
loop in Ruby really uses the.each
method behind the scenes. ... Although, I can't recall where I learned that. -
I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the
for
loop variables are not loop scoped, as ineach
. -
Came across this link:
http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/On that list it says
@unknownuser said:Use parallel assignment (a, b = 5, 6) where applicable
while at this link:
http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html@unknownuser said:
Avoid parallel assignment
-
@thomthom said:
Came across this link:
http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/On that list it says
@unknownuser said:Use parallel assignment (a, b = 5, 6) where applicable
while at this link:
http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html@unknownuser said:
Avoid parallel assignment
I just bought the ebook and that review summary was wrong - parallel assignments are not recommended for performance important tasks.
Interesting read that book btw. -
Let's see - for performance I'm going to avoid iterations, arrays, hashes and objects.
What's left?
-
-
@jim said:
I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the
for
loop variables are not loop scoped, as ineach
."Your racing car is not faster than my Trabant, it just covers more ground in a shorter time than my car."
-
Has anyone looked into Enumerable.grep()? it seems pretty useful, but I don't know how fast it is.
-
@adamb said:
@jim said:
I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the
for
loop variables are not loop scoped, as ineach
."Your racing car is not faster than my Trabant, it just covers more ground in a shorter time than my car."
Heh? Oh. Yes, I see.
Would it be correct to say: An each loop can be as fast as a for loop if the loop variable has been initialized?
-
That would mean it's not the each loop itself that's slow - but the creation of variables.
Advertisement