Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Json11 Benchmarks #41

Open
loretoparisi opened this issue Oct 13, 2015 · 2 comments
Open

Json11 Benchmarks #41

loretoparisi opened this issue Oct 13, 2015 · 2 comments

Comments

@loretoparisi
Copy link

First I want to thank you @dropbox to share this project.
I'm handling this simple json benchmark project https://github.com/loretoparisi/ios-json-benchmark
Here some results compared to well known parsers (C++, Objective-C so far only) for mobile devices and not like JSONKit, Gason, RapidJSON, Apple's NSJSONSerialization (more to come). I have integrated Json11

The integration is as simple as

#import "json11.hpp"

@implementation Json11

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

    const char* data = [json UTF8String];

    json11::Json parser;

    parser = json11::Json(data);

    std::string jsonString;

    parser.dump(jsonString);

    return [NSString stringWithstring:jsonString];

}

@end

where [NSString stringWithstring:jsonString] converts a std:string to a iOS Foundation NSString

5 times parsing of a 322 Bytes JSON file
schermata 2015-10-13 alle 22 05 02

1 times parsing of a 55435 Bytes JSON file
schermata 2015-10-13 alle 22 01 01

100 times parsing of a 55435 Bytes JSON file
schermata 2015-10-13 alle 22 01 40

@loretoparisi loretoparisi changed the title Json11 perfomances Json11 Benchmarks Oct 13, 2015
@artwyman
Copy link
Contributor

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.

@loretoparisi
Copy link
Author

@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

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

No branches or pull requests

2 participants