Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonLdUtils.DeepCompare(...): poor performance on large arrays #29

Closed
dtivel opened this issue Jun 29, 2018 · 1 comment · Fixed by #30
Closed

JsonLdUtils.DeepCompare(...): poor performance on large arrays #29

dtivel opened this issue Jun 29, 2018 · 1 comment · Fixed by #30

Comments

@dtivel
Copy link
Collaborator

dtivel commented Jun 29, 2018

Version 1.0.4

JsonLD.Core.JsonLdUtils.DeepCompare(...) has poor performance when comparing large arrays. With the provided repro (below) it takes ~4 seconds to perform a deep comparison on two objects.

Repro:

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using JsonLD.Core;
using Newtonsoft.Json.Linq;

class Program
{
    private static void Main()
    {
        try
        {
            Test();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }

    private static void Test()
    {
        var uri = new Uri("https://az635243.vo.msecnd.net/v3-catalog0/data/2018.06.27.19.19.02/test20180627163712.1.0.485.json");
        var request = WebRequest.CreateHttp(uri);
        JToken token1;
        JToken token2;

        using (var response = request.GetResponse())
        using (var stream = response.GetResponseStream())
        using (var reader = new StreamReader(stream))
        {
            var json = reader.ReadToEnd();

            token1 = JObject.Parse(json);
            token2 = JObject.Parse(json);
        }

        Test(() => JsonLdUtils.DeepCompare(token1, token2), times: 10);
    }

    private static void Test(Action action, int times)
    {
        var stopwatch = new Stopwatch();

        for (var i = 0; i < times; ++i)
        {
            stopwatch.Restart();

            action();

            Console.WriteLine(stopwatch.Elapsed.TotalSeconds);
        }
    }
}
@goofballLogic
Copy link
Member

This should be reconsidered as part of #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants