What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To u.GetViewBounds .X +
u.GetViewBounds .Width
For y As Integer = u.GetViewBounds .Y To
u.GetViewBounds .Y + u.GetViewBounds .Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint (x, y)
End If
Next
Next
or
dim vr as rectangle=u.Get ViewBounds
For x As Integer = vr.X To vr.X + vr.Width
For y As Integer = vr.Y To vr.Y + vr.Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint (x, y)
End If
Next
Next
Should I declare a variable as rectangle?
I'm not sure how compiler will optimize this and a call to u.GetViewBounds
each time is looping is a speed problem to me
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------ 5 1083
Crirus,
IMHO, the second way will be faster because you only execute "GetViewBou nds"
once.
You could always use the "With" clause to achieve the same effect.
Generally if you have to do something like:
a.b.z = a.b.x + a.b.y
Then it would be more efficient to use:
With a.b
.z = .x + .y
End With
The advantage is even greater if a.b is a function that takes time to
execute.
The VB compiler probably does some optimizations with fields as opposed to
properties and methods.
Hope this helps,
Trev.
"Crirus" <Cr****@datagro up.ro> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To u.GetViewBounds .X
+ u.GetViewBounds .Width For y As Integer = u.GetViewBounds .Y To u.GetViewBounds .Y + u.GetViewBounds .Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
or
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For y As Integer = vr.Y To vr.Y + vr.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
Should I declare a variable as rectangle? I'm not sure how compiler will optimize this and a call to u.GetViewBounds each time is looping is a speed problem to me
-- Cheers, Crirus
------------------------------ If work were a good thing, the boss would take it all from you
------------------------------
Crirus, dim vr as rectangle=u.Get ViewBounds Should I declare a variable as rectangle?
I don't think that is going to make a worthwhile change to the function.
Instead of Rectangle.X + Rectangle.Width , I would use Rectangle.Right . (or
Rectangle.Botto m), however I don't think this will make a worth while change
either (IMHO it makes it more readable).
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width
For x As Integer = vr.Left to vr.Right
Remember the vr.Left is the same as vr.X. Again readability not
performance...
However you should be able to reduce this to some rather interesting
formulas. Coming up with these formulas (this algorithm) I think is where
you are going to gain your performance boost!
From the code it appears you "simply" want the intersection of a circle with
a Rectangle? Correct? For the points that interest you want to call
AddCorrectPoint ? Correct?
Searching google for "intersecti on circle rectangle" returns some
interesting and promising results...
Off hand:
for each row
find min col intersecting circle, limit to bounds
find max col intersecting circle, limit to bounds
for min col to max col
AddCorrectPoint
The intersection of a line with a circle should be a "simple formula"... http://mathworld.wolfram.com/Circle-...ersection.html
Its been too long since I've had geometry ;-)
Hope this helps
Jay
"Crirus" <Cr****@datagro up.ro> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To u.GetViewBounds .X
+ u.GetViewBounds .Width For y As Integer = u.GetViewBounds .Y To u.GetViewBounds .Y + u.GetViewBounds .Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
or
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For y As Integer = vr.Y To vr.Y + vr.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
Should I declare a variable as rectangle? I'm not sure how compiler will optimize this and a call to u.GetViewBounds each time is looping is a speed problem to me
-- Cheers, Crirus
------------------------------ If work were a good thing, the boss would take it all from you
------------------------------
Well, actualy, I simply need points inside the circle.. the rectangleis the
bounding one already :)
I was just wandering if the call to the property is better than allocating
temporary variables to hold properties values
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uV******** *****@tk2msftng p13.phx.gbl... Crirus, dim vr as rectangle=u.Get ViewBounds Should I declare a variable as rectangle? I don't think that is going to make a worthwhile change to the function.
Instead of Rectangle.X + Rectangle.Width , I would use Rectangle.Right . (or Rectangle.Botto m), however I don't think this will make a worth while
change either (IMHO it makes it more readable).
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For x As Integer = vr.Left to vr.Right
Remember the vr.Left is the same as vr.X. Again readability not performance...
However you should be able to reduce this to some rather interesting formulas. Coming up with these formulas (this algorithm) I think is where you are going to gain your performance boost!
From the code it appears you "simply" want the intersection of a circle
with a Rectangle? Correct? For the points that interest you want to call AddCorrectPoint ? Correct?
Searching google for "intersecti on circle rectangle" returns some interesting and promising results...
Off hand: for each row find min col intersecting circle, limit to bounds find max col intersecting circle, limit to bounds for min col to max col AddCorrectPoint
The intersection of a line with a circle should be a "simple formula"...
http://mathworld.wolfram.com/Circle-...ersection.html
Its been too long since I've had geometry ;-)
Hope this helps Jay
"Crirus" <Cr****@datagro up.ro> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To
u.GetViewBounds .X + u.GetViewBounds .Width For y As Integer = u.GetViewBounds .Y To u.GetViewBounds .Y + u.GetViewBounds .Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange *
u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
or
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For y As Integer = vr.Y To vr.Y + vr.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange *
u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
Should I declare a variable as rectangle? I'm not sure how compiler will optimize this and a call to
u.GetViewBounds each time is looping is a speed problem to me
-- Cheers, Crirus
------------------------------ If work were a good thing, the boss would take it all from you
------------------------------
> I was just wandering if the call to the property is better than allocating temporary variables to hold properties values
IMHO, it depends on how the property is implemented. If it is a simple field
retrieval, then the compiler should optimise it so speed should be pretty
much the same as if you assigned it to a local variable. However, if the
property get procedure does some calculation to produce the value, then
assigning to a local variable should have a definite speed advantage.
If in doubt, always assign to a local variable or use a "with" block.
HTH,
Trev.
"Crirus" <Cr****@hotmail .com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl... Well, actualy, I simply need points inside the circle.. the rectangleis
the bounding one already :) I was just wandering if the call to the property is better than allocating temporary variables to hold properties values
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:uV******** *****@tk2msftng p13.phx.gbl... Crirus, dim vr as rectangle=u.Get ViewBounds Should I declare a variable as rectangle? I don't think that is going to make a worthwhile change to the function.
Instead of Rectangle.X + Rectangle.Width , I would use Rectangle.Right .
(or Rectangle.Botto m), however I don't think this will make a worth while change either (IMHO it makes it more readable).
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For x As Integer = vr.Left to vr.Right
Remember the vr.Left is the same as vr.X. Again readability not performance...
However you should be able to reduce this to some rather interesting formulas. Coming up with these formulas (this algorithm) I think is
where you are going to gain your performance boost!
From the code it appears you "simply" want the intersection of a circle with a Rectangle? Correct? For the points that interest you want to call AddCorrectPoint ? Correct?
Searching google for "intersecti on circle rectangle" returns some interesting and promising results...
Off hand: for each row find min col intersecting circle, limit to bounds find max col intersecting circle, limit to bounds for min col to max col AddCorrectPoint
The intersection of a line with a circle should be a "simple formula"...
http://mathworld.wolfram.com/Circle-...ersection.html
Its been too long since I've had geometry ;-)
Hope this helps Jay
"Crirus" <Cr****@datagro up.ro> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To u.GetViewBounds .X + u.GetViewBounds .Width For y As Integer = u.GetViewBounds .Y To u.GetViewBounds .Y + u.GetViewBounds .Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
or
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For y As Integer = vr.Y To vr.Y + vr.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
Should I declare a variable as rectangle? I'm not sure how compiler will optimize this and a call to u.GetViewBounds each time is looping is a speed problem to me
-- Cheers, Crirus
------------------------------ If work were a good thing, the boss would take it all from you
------------------------------
Crirus, Well, actualy, I simply need points inside the circle.. the rectangleis
the bounding one already :)
Which is where I still recommend finding a new algorithm instead of tweaking
the existing algorithm. By tweaking I mean calling a property or allocating
temporary variables, as the optimizer can do that for you behind the
scenes...
I'm recommending finding a new engine to course tune the car, once you have
a good engine, then worry about fine tuning it. I realize sometimes you need
to go with the engine you have ;-)
I was just wandering if the call to the property is better than allocating temporary variables to hold properties values
To truely answer this question you will need to profile it! Run what you
have through a profiler, change it run the change thru a profiler. Compare
the results. As Codemonkey stated, for simple fields, the optimizer should
inline the property method. However there are too many factors involved to
give you a general answer, as the general answer could change based on other
code...
Using "Rectangle. X + Rectangle.Width " instead of "Rectangle.Righ t" is
something you should also profile, the optimizer might move "Rectangle. X +
Rectangle.Width " outside the loop as the value does not change inside the
loop. I don't remember if the JIT does this optimization or not.
The following articles provide information on writing .NET code that
performs well. http://msdn.microsoft.com/library/de...anagedcode.asp http://msdn.microsoft.com/library/de...anagedapps.asp http://msdn.microsoft.com/library/de...vbnstrcatn.asp http://msdn.microsoft.com/library/de...tchperfopt.asp http://msdn.microsoft.com/library/de...tperftechs.asp
Hope this helps
Jay
"Crirus" <Cr****@hotmail .com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl... Well, actualy, I simply need points inside the circle.. the rectangleis
the bounding one already :) I was just wandering if the call to the property is better than allocating temporary variables to hold properties values
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:uV******** *****@tk2msftng p13.phx.gbl... Crirus, dim vr as rectangle=u.Get ViewBounds Should I declare a variable as rectangle? I don't think that is going to make a worthwhile change to the function.
Instead of Rectangle.X + Rectangle.Width , I would use Rectangle.Right .
(or Rectangle.Botto m), however I don't think this will make a worth while change either (IMHO it makes it more readable).
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For x As Integer = vr.Left to vr.Right
Remember the vr.Left is the same as vr.X. Again readability not performance...
However you should be able to reduce this to some rather interesting formulas. Coming up with these formulas (this algorithm) I think is
where you are going to gain your performance boost!
From the code it appears you "simply" want the intersection of a circle with a Rectangle? Correct? For the points that interest you want to call AddCorrectPoint ? Correct?
Searching google for "intersecti on circle rectangle" returns some interesting and promising results...
Off hand: for each row find min col intersecting circle, limit to bounds find max col intersecting circle, limit to bounds for min col to max col AddCorrectPoint
The intersection of a line with a circle should be a "simple formula"...
http://mathworld.wolfram.com/Circle-...ersection.html
Its been too long since I've had geometry ;-)
Hope this helps Jay
"Crirus" <Cr****@datagro up.ro> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds .X To u.GetViewBounds .X + u.GetViewBounds .Width For y As Integer = u.GetViewBounds .Y To u.GetViewBounds .Y + u.GetViewBounds .Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
or
dim vr as rectangle=u.Get ViewBounds For x As Integer = vr.X To vr.X + vr.Width For y As Integer = vr.Y To vr.Y + vr.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual AddCorrectPoint (x, y) End If Next Next
Should I declare a variable as rectangle? I'm not sure how compiler will optimize this and a call to u.GetViewBounds each time is looping is a speed problem to me
-- Cheers, Crirus
------------------------------ If work were a good thing, the boss would take it all from you
------------------------------
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Murat Tasan |
last post by:
how well is javac from sun's jdk tools optimized?
wow, that's a general question... so i guess here is a simple example...
let's say i have a program that uses an array.
and many times in the program i need to do computation that rely on the
array's length.
so, how much speedup (if any at all) is there to storing the array length
as an int and using that in the computations, compared with constantly
using the arrayName.length method?
|
by: user |
last post by:
Hello,
Here is the program
#include stdio
int main(void)
{
const int num = 100;
int *ip;
|
by: Marc Pelletier |
last post by:
Hello,
Are nested function calls inefficient (or inherently evil)? In Delphi
I've seen small but significant performance improvements by always
declaring a local variable and 'unwrapping' the nested calls, but I'm not
convinced it is necessarily so in c#. So for example:
public struct TideValue {
public TideValue( double Time, double Height )
{
|
by: Axel Bock |
last post by:
Hi all,
I am trying to get my head around what happens if I return a class
object from a function.
It seems C++ (MinGW) does not invoke the copy constructor if I do
something like this:
SomeObj foo()
{
SomeObj X;
|
by: Robbie Hatley |
last post by:
Hello, group. I've been doing too much C++ programming lately, and
I'm starting to become rusty at some aspects of the C way of doing
things, esp. efficient low-level data copies.
Specificially, I just wrote the following, but I don't know if this
is safe:
void Func(char* left, char* right)
{
chat temp_left = {'\0'};
| |
by: JoeC |
last post by:
I have been writing games and I also read about good programming
techniques. I tend to create large objects that do lots of things. A
good example I have is a unit object. The object controls and holds
everything a unit in my game is supposed to do. What are some some
cures for this kind of large object or are they OK because they
represent one thing. If not what are better ways to design objects
that behave the same way. Would it be...
|
by: Avalon1178 |
last post by:
Hi,
I have an application that periodically uses a std::string variable
which is assigned a VERY VERY large string (15000000+ bytes long).
This application is essentially a daemon, and it polls a data set
which can have a lot of information and it is concatenated in this
single string variable object. When the daemon finishes its job, it
goes to sleep, but before doing so, it "clears" this variable so it
can be reused again in the next...
|
by: runa2104 |
last post by:
Interview Question
Visit this site it is really good question on C language.
http://techinterviewquestion.blogspot.com/2007/05/c-question.html
|
by: Dave S |
last post by:
Hi All,
I have been given some code to wok on. It relies heavily on the
optimiser to run at the correct speed. With this in mind I have been
loking through it to see if I can help it out a bit. I have limitied
knowledge of how compilers works, but I understand that some
constructs optimise easier / better. We are using a variant of gcc
(3.4.1 I think) on Nios II platform, if that makes a difference.
The question I have is are these 2...
|
by: Herbert Kleebauer |
last post by:
As part of a simple X demo for Linux I send the byte string
in "send8" to the X server. This byte string displays a circle
at the x/y position send8.s8x/send8.s8y. In "display()" a 8x8
grid of circles is displayed. But when I compile the code
below with -O3, then in the "j" loop not send8.s8x is incremented
by 50 (send8.s8x += 50;) but only a local copy of it. As a result,
the byte string sent to the X server (x_send((char*)&send8,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |