Click here to Skip to main content
15,887,966 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Newbie - Vector Printing of Visio Document using AxVisioViewer ActiveX control. Pin
Eddy Vluggen2-May-18 7:36
professionalEddy Vluggen2-May-18 7:36 
GeneralRe: C# Newbie - Vector Printing of Visio Document using AxVisioViewer ActiveX control. Pin
chubbsy22-May-18 1:46
chubbsy22-May-18 1:46 
GeneralRe: C# Newbie - Vector Printing of Visio Document using AxVisioViewer ActiveX control. Pin
Eddy Vluggen22-May-18 1:48
professionalEddy Vluggen22-May-18 1:48 
QuestioniTextSharp - Saving file to a remote server Pin
User 136751141-May-18 22:21
User 136751141-May-18 22:21 
AnswerRe: iTextSharp - Saving file to a remote server Pin
Jochen Arndt2-May-18 1:46
professionalJochen Arndt2-May-18 1:46 
GeneralRe: iTextSharp - Saving file to a remote server Pin
User 136751142-May-18 1:50
User 136751142-May-18 1:50 
GeneralRe: iTextSharp - Saving file to a remote server Pin
Jochen Arndt2-May-18 2:00
professionalJochen Arndt2-May-18 2:00 
QuestionSIMD Experiment (System.Numeric.Vectors.Vector2 test) Pin
Super Lloyd29-Apr-18 16:12
Super Lloyd29-Apr-18 16:12 
[EDIT] There was a bug in VectorDot, now corrected. Vector2 doing better.

I am trying to compare various operation with normal .NET struct vs SIMD / System.Numerics.Vectors.Vector2 one.

I created this plain C# normal struct and SIMD extensions:
C#
    public struct Point2
    {
        public float X, Y;

<pre>
    public Point2(float x, float y)
    {
        X = x;
        Y = y;
    }

    public float Dot(Point2 p) => X * p.X + Y * p.Y;
    public static Point2 operator +(Point2 p, Point2 p2) => new Point2(p.X + p2.X, p.Y + p2.Y);

    public static float operator ^(Point2 p, Point2 p2) => p.Cross(p2);
    public float Cross(Point2 p2)
    {
        return X * p2.Y - Y * p2.X;
    }
}

public static class VectorExtensions
{
    public static float Cross(this Vector2 v, Vector2 v2)
    {
        return v.X * v2.Y - v.Y * v2.X;
    }
}</pre>

And made this text program
    class Program
    {
        static void Main(string[] args)
        {
            int N = 10_000_000;

<pre>
        DoVectorCross(1);
        using (new MeasureBlock("Vectors Cross"))
            DoVectorCross(N);

        DoPointCross(1);
        using (new MeasureBlock("Points Cross"))
            DoPointCross(N);

        DoVectorDot(1);
        using (new MeasureBlock("Vectors Dots"))
            DoVectorDot(N);

        DoPointDot(1);
        using (new MeasureBlock("Points Dots"))
            DoPointCross(N);

        DoVectorAdd(1);
        using (new MeasureBlock("Vectors Add"))
            DoVectorAdd(N);

        DoPointAdd(1);
        using (new MeasureBlock("Points Add"))
            DoPointAdd(N);

        Console.ReadLine();
    }

    static float DoVectorCross(int N)
    {
        var v1 = new Vector2(1, 2);
        var v2 = new Vector2(2, 3);
        float result = 0;
        for (int i = 0; i < N; i++)
            result += v1.Cross(v2);
        return result;
    }
    static float DoVectorDot(int N)
    {
        var v1 = new Vector2(1, 2);
        var v2 = new Vector2(2, 3);
        float result = 0;
        for (int i = 0; i < N; i++)
            result += Vector2.Dot(v1, v2);
        return result;
    }
    static Vector2 DoVectorAdd(int N)
    {
        var v1 = new Vector2(1, 2);
        var v2 = new Vector2(2, 3);
        for (int i = 0; i < N; i++)
            v1 += v2;
        return v1;
    }
    static float DoPointCross(int N)
    {
        var v1 = new Point2(1, 2);
        var v2 = new Point2(2, 3);
        float result = 0;
        for (int i = 0; i < N; i++)
            result += v1.Cross(v2);
        return result;
    }
    static float DoPointDot(int N)
    {
        var v1 = new Point2(1, 2);
        var v2 = new Point2(2, 3);
        float result = 0;
        for (int i = 0; i < N; i++)
            result += v1.Dot(v2);
        return result;
    }
    static Point2 DoPointAdd(int N)
    {
        var v1 = new Point2(1, 2);
        var v2 = new Point2(2, 3);
        for (int i = 0; i < N; i++)
            v1 += v2;
        return v1;
    }
}</pre>

I get the following measurement for each compile target (x86, x64/ AnyCPU):
x64
Vectors Cross took 24ms.
Points Cross took 17ms.
Vectors Dots took 16ms.
Points Dots took 21ms.
Vectors Add took 35ms.
Points Add took 109ms.

x86
Vectors Cross took 41ms.
Points Cross took 38ms.
Vectors Dots took 49ms.
Points Dots took 40ms.
Vectors Add took 38ms.
Points Add took 47ms.

AnyCPU
Vectors Cross took 40ms.
Points Cross took 39ms.
Vectors Dots took 43ms.
Points Dots took 39ms.
Vectors Add took 49ms.
Points Add took 58ms.

Vector2 has now similar performance to Point2, except when compiled for x64, Dot() is 25% faster and Add() is 3 times faster.
Custom Cross() operations is slower though.. How do I write efficient Cross operation?
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 29-Apr-18 23:10pm.

AnswerRe: SIMD Experiment (System.Numeric.Vectors.Vector2 test) Pin
Jochen Arndt1-May-18 23:41
professionalJochen Arndt1-May-18 23:41 
GeneralRe: SIMD Experiment (System.Numeric.Vectors.Vector2 test) Pin
Super Lloyd2-May-18 2:35
Super Lloyd2-May-18 2:35 
GeneralRe: SIMD Experiment (System.Numeric.Vectors.Vector2 test) Pin
Jochen Arndt2-May-18 2:48
professionalJochen Arndt2-May-18 2:48 
QuestionSystem.Numerics.Vectors (SIMD) Pin
Super Lloyd29-Apr-18 14:40
Super Lloyd29-Apr-18 14:40 
Questionlibvlc dll with network streaming is not working Pin
Member 1288274528-Apr-18 19:34
Member 1288274528-Apr-18 19:34 
AnswerRe: libvlc dll with network streaming is not working Pin
Jochen Arndt29-Apr-18 1:09
professionalJochen Arndt29-Apr-18 1:09 
GeneralRe: libvlc dll with network streaming is not working Pin
Member 1288274529-Apr-18 19:01
Member 1288274529-Apr-18 19:01 
GeneralRe: libvlc dll with network streaming is not working Pin
Jochen Arndt29-Apr-18 21:10
professionalJochen Arndt29-Apr-18 21:10 
GeneralRe: libvlc dll with network streaming is not working Pin
Member 1288274529-Apr-18 23:15
Member 1288274529-Apr-18 23:15 
GeneralRe: libvlc dll with network streaming is not working Pin
Member 128827452-May-18 19:33
Member 128827452-May-18 19:33 
QuestionTax Calculator using C# in a Cross Platform file. Pin
Aishah Alsaadi28-Apr-18 2:21
professionalAishah Alsaadi28-Apr-18 2:21 
AnswerRe: Tax Calculator using C# in a Cross Platform file. Pin
OriginalGriff28-Apr-18 2:43
mveOriginalGriff28-Apr-18 2:43 
AnswerRe: Tax Calculator using C# in a Cross Platform file. Pin
hamid1829-Apr-18 23:48
hamid1829-Apr-18 23:48 
QuestionUWP / VisualStudio 2017 and StackOverflowException Pin
Super Lloyd26-Apr-18 21:07
Super Lloyd26-Apr-18 21:07 
GeneralRe: UWP / VisualStudio 2017 and StackOverflowException Pin
Richard MacCutchan26-Apr-18 22:47
mveRichard MacCutchan26-Apr-18 22:47 
QuestionRe: UWP / VisualStudio 2017 and StackOverflowException Pin
Super Lloyd27-Apr-18 0:35
Super Lloyd27-Apr-18 0:35 
AnswerRe: UWP / VisualStudio 2017 and StackOverflowException Pin
Richard MacCutchan27-Apr-18 2:00
mveRichard MacCutchan27-Apr-18 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.