Skip to content

Commit

Permalink
Improvement hex parsing performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Mamchur committed Nov 10, 2013
1 parent f133e75 commit 9031a15
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (void)didReceiveMemoryWarning

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mesh" ofType:@"json"];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"twitter_public_timeline" ofType:@"json"];
self.data = [NSData dataWithContentsOfFile:filePath];
[super viewDidLoad];
}
Expand All @@ -75,7 +75,7 @@ - (IBAction)parse:(id)sender {
clock_get_time(cclock, &start);

size_t l = [data length];
const int COUNT = 100;
const int COUNT = 1000;
for (int i = 0; i < COUNT; i++) {
@autoreleasepool {
JsonLiteParser *parser = [JsonLiteParser parserWithDepth:512];
Expand All @@ -91,7 +91,7 @@ - (IBAction)parse:(id)sender {
time += (double)(end.tv_nsec - start.tv_nsec) / 1000000000;
double speed = (double)l * COUNT / 1024 / 1024 / time;

NSString *jsonlite = [NSString stringWithFormat:@"Time - %f µs\nSpeed - %.2f MBps", time, speed];
NSString *jsonlite = [NSString stringWithFormat:@"Time - %f s\nSpeed - %.2f MBps", time, speed];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@""
message:jsonlite
delegate:nil
Expand All @@ -112,7 +112,7 @@ - (IBAction)parse1:(id)sender {
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &start);

const int COUNT = 100;
const int COUNT = 1000;
char parser[1024];
for (int i = 0; i < COUNT; i++) {
jsonlite_parser p = jsonlite_parser_init_memory(parser, sizeof(parser));
Expand All @@ -126,7 +126,7 @@ - (IBAction)parse1:(id)sender {
time += (double)(end.tv_nsec - start.tv_nsec) / 1000000000;
double speed = (double)l * COUNT / 1024 / 1024 / time;

NSString *jsonlite = [NSString stringWithFormat:@"Time - %f µs\nSpeed - %.2f MBps", time, speed];
NSString *jsonlite = [NSString stringWithFormat:@"Time - %f s\nSpeed - %.2f MBps", time, speed];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@""
message:jsonlite
delegate:nil
Expand Down
19 changes: 7 additions & 12 deletions jsonlite/include/jsonlite_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extern "C" {
* @param ts jsonlite token
* @return 0 if ts is NULL; otherwise required size of for token conversion.
*/
size_t jsonlite_token_decode_size_for_uft8(jsonlite_token *ts);
size_t jsonlite_token_size_of_uft8(jsonlite_token *ts);

/** @brief Converts specified token to UTF-8 string.
*
Expand All @@ -172,13 +172,13 @@ extern "C" {
* @param ts jsonlite token
* @return length in bytes of converted string.
*/
size_t jsonlite_token_decode_to_uft8(jsonlite_token *ts, uint8_t **buffer);
size_t jsonlite_token_to_uft8(jsonlite_token *ts, uint8_t **buffer);

/** @brief Returns a size of memory that is required for token conversion to UTF-16 string.
* @param ts jsonlite token
* @return 0 if ts is NULL; otherwise required size of for token conversion.
*/
size_t jsonlite_token_decode_size_for_uft16(jsonlite_token *ts);
size_t jsonlite_token_size_of_uft16(jsonlite_token *ts);

/** @brief Converts specified token to UTF-16 string.
*
Expand All @@ -189,15 +189,10 @@ extern "C" {
* @param ts jsonlite token
* @return length in bytes of converted string.
*/
size_t jsonlite_token_decode_to_uft16(jsonlite_token *ts, uint16_t **buffer);

/** @brief Converts hex digit to integer value.
*
* @param c a ASCII character.
* @return integer value of hex character,
* if character belongs to set [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f]; otherwise 0xFF.
*/
uint8_t jsonlite_hex_char_to_uint8(uint8_t c);
size_t jsonlite_token_to_uft16(jsonlite_token *ts, uint16_t **buffer);

long jsonlite_token_to_long(jsonlite_token *token);
long long jsonlite_token_to_long_long(jsonlite_token *token);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 9031a15

Please sign in to comment.