Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
AnswerRe: I need to get the next next text from text file Pin
Richard MacCutchan5-May-18 3:21
mveRichard MacCutchan5-May-18 3:21 
AnswerRe: I need to get the next next text from text file Pin
OriginalGriff5-May-18 3:27
mveOriginalGriff5-May-18 3:27 
AnswerRe: I need to get the next next text from text file Pin
Gerry Schmitz5-May-18 4:35
mveGerry Schmitz5-May-18 4:35 
QuestionOpenTK and text Pin
Leif Simon Goodwin4-May-18 5:39
Leif Simon Goodwin4-May-18 5:39 
QuestionBind JSON data to rows in a table MVC4 issue Pin
Member 127814644-May-18 4:06
Member 127814644-May-18 4:06 
AnswerRe: Bind JSON data to rows in a table MVC4 issue Pin
Afzaal Ahmad Zeeshan4-May-18 8:21
professionalAfzaal Ahmad Zeeshan4-May-18 8:21 
GeneralRe: Bind JSON data to rows in a table MVC4 issue Pin
Member 127814647-May-18 4:32
Member 127814647-May-18 4:32 
Questionc# GridView. Displaying tables in dropdownlist, selecting and editing them. Pin
trottl4-May-18 2:07
trottl4-May-18 2:07 
AnswerRe: c# GridView. Displaying tables in dropdownlist, selecting and editing them. Pin
Gerry Schmitz5-May-18 4:39
mveGerry Schmitz5-May-18 4:39 
GeneralRe: c# GridView. Displaying tables in dropdownlist, selecting and editing them. Pin
trottl10-May-18 0:47
trottl10-May-18 0:47 
GeneralRe: c# GridView. Displaying tables in dropdownlist, selecting and editing them. Pin
trottl10-May-18 1:15
trottl10-May-18 1:15 
AnswerRe: c# GridView. Displaying tables in dropdownlist, selecting and editing them. Pin
trottl14-May-18 1:59
trottl14-May-18 1:59 
QuestionC# Newbie - Vector Printing of Visio Document using AxVisioViewer ActiveX control. Pin
chubbsy1-May-18 23:02
chubbsy1-May-18 23:02 
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 

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.