Math question

Is there a reason why identical math operations in one Silverlight application will be significantly longer than in another?

For example, I have code that takes a list of points and converts them (scales and translates them) and populates another list of points. It is important that I keep the starting points intact, hence the second list.

Here's the corresponding code (scale is double, and origin is a point):

public Point transformPoint(Point point) {
        // scale, then translate the x
        point.X = (point.X - origin.X) * scale;
        // scale, then translate the y
        point.Y = (point.Y - origin.Y) * scale;
        // return the point
        return point;
    }

Here's how I do the cycle and time, in case it matters:

            DateTime startTime = DateTime.Now;
        foreach (Point point in rawPoints) transformedPoints.Add(transformPoint(point));
        Debug.Print("ASPX milliseconds: {0}", (DateTime.Now - startTime).Milliseconds);

When you run 14356 points (don’t ask, he modeled the real world number in the desktop application), the breakdown is as follows:

Silverlight application # 1: 46 ms

Silverlight app # 2: 859 ms

- , MainPage. , , . , , ?

, - , - , .

+3
3

.

, MainPage. IWO Silverlight , .

. , , . .

. , ? . ( ), , parrallel , . ( , StopWatch ) , , . , (, ), .

+2

, Silverlight App # 2 . ~ 15 000 , .

. transformPoints , ?

GC, .

+1

Is it possible that your code will not be installed in the CLR by an application that runs slower?

I'm not sure how the CLR in SL handles inlining, but here is a link to some of the prerequisites for inlining in 3.5 SP1.

http://udooz.net/blog/2009/04/clr-improvements-in-net-35-sp1/

0
source

Source: https://habr.com/ru/post/1719762/


All Articles