- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I have been watching to much TV,in particular the TV detective Mr Monk (Obsessive compulsive, feels the need to tidy upany mess he sees!)
I get like that when I look at code :-)
Some code I am looking at has *lots* of
call fill(n, value, array)
which does a loop 1 to n and assigns the scalar "value" to the array element-by-element
My "Mr Monk" instinct was to replace these calls with simple
array = value
statements
But I needed to know if it would make any actual difference to the performance.
So I did a simple test using cpu_time one around a loop which called "fill" lots of times and another around a loop which used array assignment.
I found that array assignment in debug mode isalmost 2/3 the time of the do loop (22.71 seconds vs 30.17 seconds)
and in release mode is less then half (3.38 second vs 8.00 seconds)
Such an improvement in performance may help me to persuadeothers that my "tidying up" *does* make a difference and not just in readability :-)
Les
I get like that when I look at code :-)
Some code I am looking at has *lots* of
call fill(n, value, array)
which does a loop 1 to n and assigns the scalar "value" to the array element-by-element
My "Mr Monk" instinct was to replace these calls with simple
array = value
statements
But I needed to know if it would make any actual difference to the performance.
So I did a simple test using cpu_time one around a loop which called "fill" lots of times and another around a loop which used array assignment.
I found that array assignment in debug mode isalmost 2/3 the time of the do loop (22.71 seconds vs 30.17 seconds)
and in release mode is less then half (3.38 second vs 8.00 seconds)
Such an improvement in performance may help me to persuadeothers that my "tidying up" *does* make a difference and not just in readability :-)
Les
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Do you compare with :
array(:)=value
This syntax looks , for me,less confusive?
Do you compare with :
array(:)=value
This syntax looks , for me,less confusive?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please, please, PLEASE! Do NOT use "array(:)" - it has subtly different semantics and can slow down the code. See Doctor, It Hurts When I Do This!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting gvautier
Hello
Do you compare with :
array(:)=value
This syntax looks , for me,less confusive?
Do you compare with :
array(:)=value
This syntax looks , for me,less confusive?
What you have there is an array section.
Even thoughit applies to the whole array it is still a section. You should only use sections when you need to refer to an actualsection. (Maybe I should do a test involving sections and equivalent do loops.)
If there is a possibility of confusion I usually add a comment before the assignment informing the personreading the code(which could be me in the future) that it is an array.
Les
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page