Giter VIP home page Giter VIP logo

Comments (2)

artwyman avatar artwyman commented on July 20, 2024

Cool! I'm really curious about the really high max values for json11 in 2 cases (and for JSONKit in one case). Caching effects of some sort (is it always the first time)? Or some kind of a one-time interruption from outside the system? I can't believe that parsing the same data sometimes legitimately takes 150x more time.

Regardless, this would be a god test case to use for some profiling, if someone felt inclined.

from json11.

loretoparisi avatar loretoparisi commented on July 20, 2024

@artwyman Yes I agree, infact that sounds quite strange to me! Also I can see a non proportional timing when parsing X times the same JSON, even if this is something that happens to several parsers.

This is the timing code (the snippet here show two parsers) in the file MCTestViewController.m

- (NSNumber *)parseWithJson11:(NSString *)content
{
    NSDate *startTime = [NSDate date];

    Json11 *rpdj = [Json11 new];
    id result=[rpdj parse:content];
    float elapsedTime = [startTime timeIntervalSinceNow] * -1000;
    if (result == nil)
    elapsedTime = -1.0;
    return [NSNumber numberWithFloat:elapsedTime];
}

- (NSNumber *)parseWithJsonModernCPlusPlus:(NSString *)content {
    NSDate *startTime = [NSDate date];

    JsonModernCPlusPlus *rpdj = [JsonModernCPlusPlus new];
    id result=[rpdj parse:content];
    float elapsedTime = [startTime timeIntervalSinceNow] * -1000;
    if (result == nil)
    elapsedTime = -1.0;
    return [NSNumber numberWithFloat:elapsedTime];
}

where as said above I do

#import "Json11.h"
#import "json11.hpp"
#import "CppStringAdditions.h"

@implementation Json11

- (NSString*)parse:(NSString*)json {

    const char* data = [json UTF8String];

    json11::Json parser;

    parser = json11::Json(data);

    std::string jsonString;

    parser.dump(jsonString);

    //printf("%s", jsonString.c_str());

    return [NSString stringWithstring:jsonString];

}
@end

Said that, I'm doing again the tests on

XCode 7.1 / iOS 9.0 / ARM64 / iPhone6

So I have tested for 1, 5 and 100 times parsing a small a 322 Bytes JSON file and a big a 55435 Bytes JSON file and tested json11, gason and JSON Forn Modern C++ (now added), that are all JSON C++ parsers.

The biggest file (uncompressed 55435 Bytes) has nested json objects like:

"track_list": [
                {
                    "track": {
                        "track_id": 72612817,
                        "track_mbid": "",
                        "track_isrc": "GBUM71400955",
                        "track_spotify_id": "",
                        "track_soundcloud_id": 0,
                        "track_xboxmusic_id": "",
                        "track_name": "Bailando (Spanish Version)",
                        "track_name_translation_list": [],
                        "track_rating": 91,
                        "track_length": 243,
                        "commontrack_id": 39807317,
                        "instrumental": 0,
                        "explicit": 0,
                        "has_lyrics": 1,
                        "has_subtitles": 1,
                        "num_favourite": 848,
                        "lyrics_id": 9615270,
                        "subtitle_id": 2871021,
                        "album_id": 19584902,
                        "album_name": "SEX AND LOVE",
                        "artist_id": 27082008,
                        "artist_mbid": "",
                        "artist_name": "Enrique Iglesias feat. Descemer Bueno & Gente de Zona",
                        "album_coverart_100x100": "http://static.musixmatch.com/images-storage/albums8/7/0/0/8/5/7/30758007.jpg",
                        "album_coverart_350x350": "http://static.musixmatch.com/images-storage/albums8/7/0/0/8/5/7/30758007_350_350.jpg",
                        "album_coverart_500x500": "http://static.musixmatch.com/images-storage/albums8/7/0/0/8/5/7/30758007_500_500.jpg",
                        "album_coverart_800x800": "http://static.musixmatch.com/images-storage/albums8/7/0/0/8/5/7/30758007_800_800.jpg",
                        "track_share_url": "https://community.musixmatch.com/lyrics/Enrique-Iglesias-feat-Descemer-Bueno-Gente-de-Zona/Bailando-%28Spanish-Version%29",
                        "track_edit_url": "https://community.musixmatch.com/lyrics/Enrique-Iglesias-feat-Descemer-Bueno-Gente-de-Zona/Bailando-%28Spanish-Version%29?utm_source=application&utm_campaign=api&utm_medium=musixmatch-iphone",
                        "commontrack_vanity_id": "Enrique-Iglesias-feat-Descemer-Bueno-Gente-de-Zona/Bailando-(Spanish-Version)",
                        "updated_time": "2014-05-26T08:55:26Z",
                        "primary_genres": {
                            "music_genre_list": [
                                {
                                    "music_genre": {
                                        "music_genre_id": 14,
                                        "music_genre_parent_id": 34,
                                        "music_genre_name": "Pop",
                                        "music_genre_name_extended": "Pop",
                                        "music_genre_vanity": "Pop"
                                    }
                                }
                            ]
                        },
                        "secondary_genres": {
                            "music_genre_list": [
                                {
                                    "music_genre": {
                                        "music_genre_id": 1117,
                                        "music_genre_parent_id": 12,
                                        "music_genre_name": "Pop Latino",
                                        "music_genre_name_extended": "Latin / Pop Latino",
                                        "music_genre_vanity": "Latin-Pop-Latino"
                                    }
                                }
                            ]
                        }
                    }
                },

The smallest json file (322 Bytes) has a simple flat structure like:

"location": {
                "GEOIP_CITY_COUNTRY_CODE": "IT",
                "GEOIP_CITY_COUNTRY_CODE3": "ITA",
                "GEOIP_CITY_COUNTRY_NAME": "Italy",
                "GEOIP_CITY": "Bologna",
                "GEOIP_CITY_CONTINENT_CODE": "EU",
                "GEOIP_LATITUDE": 44.4938,
                "GEOIP_LONGITUDE": 11.3387
            }

####1 times parsing of a 55435 Bytes JSON file####
screen shot 2015-10-14 at 10 26 12

screen shot 2015-10-14 at 10 26 17

####5 times parsing of a 55435 Bytes JSON file####
screen shot 2015-10-14 at 10 26 32

screen shot 2015-10-14 at 10 26 35

####100 times parsing of a 55435 Bytes JSON file####
screen shot 2015-10-14 at 10 26 49

screen shot 2015-10-14 at 10 26 52

####1 time 322 Bytes JSON file####
screen shot 2015-10-14 at 10 27 02

screen shot 2015-10-14 at 10 27 05

####5 times 322 Bytes JSON file####
screen shot 2015-10-14 at 10 27 14

screen shot 2015-10-14 at 10 27 17

####100 times 322 Bytes JSON file####
screen shot 2015-10-14 at 10 27 25

screen shot 2015-10-14 at 10 27 28

from json11.

Related Issues (20)

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.