Giter Club home page Giter Club logo

jsonperf's Introduction

jsonperf

This is a project inspired by a blog post by Apple about JSON parsing. The idea is to compare popular JSON mappers and native parsing against each other using Xcode's performance test (as part of the XCTest suite). The exception to this is Big Nerd Ranch's Freddy (in which they wrote their own parser).


how it's done

see NormalPerfTest.swift

func testNormalPerformance() {
    self.measure {
        do {
            guard let json = try JSONSerialization.jsonObject(with: self.data!) as? MyJSON,
                let items = json["items"] as? [MyJSON] else {
                    XCTFail("bad JSON")
                    return
            }

            _ = try items.map{
                try Repo(myJson: $0)
            }
        } catch {
            XCTFail("bad json")
        }
    }
}

The idea is to parse data into a JSON object and then pass that object to the initializer of each mapper. Each JSON mapping package/technique has its own test class (because of some naming overlaps between imports). The data used to generate the JSON is a computed variable in an extension on XCTestCase. Doing this allows the tests to isolate the steps of creating an object after a network call has been made.

Using the measure block allows me to run the test ten times and create a baseline with a standard deviation. These numbers then allow us, as developers, to compare the packages and choose which makes the most sense for our projects.


check it out yourself!

I encourage you to pull this project and check out the results (I was a bit surprised)! In order to do so, be sure you have Cocoapods installed -- as that's how I imported the parsing packages. Simply pull the code and:

$ cd ~/path/to/source
$ pod install

packages used in this project

If I've missed a package you'd like to be tested either create an issue, pull request, or send me a tweet @mdiasdev.

jsonperf's People

Contributors

mdiasdev avatar vinnyt avatar

Watchers

 avatar  avatar

Forkers

vinnyt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.