Files
HTMLKit/HTMLKitTests/HTMLKitTokenizerPerformance.m
T
iska 4158ef0237 Use a accumulator-character-token in the tokenizer to reduce the initialization overhead
Initializing character tokens, and the NSString objects they use, results in a relatively high overhead. The tokenizer
now accumulated all successive characters in on accumulator token until a non-character token is emitted.

This change reduces the execution time of the performance test on the local machine by 48% (reference to baseline)
2015-04-11 22:12:51 +02:00

34 lines
775 B
Objective-C

//
// HTMLKitTokenizerPerformance.m
// HTMLKit
//
// Created by Iska on 23/03/15.
// Copyright (c) 2015 BrainCookie. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "HTMLTokenizer.h"
#import "HTMLTokenizerStates.h"
#import "HTMLTokens.h"
@interface HTMLKitTokenizerPerformance : XCTestCase
@end
@implementation HTMLKitTokenizerPerformance
- (void)testTokenizerPerformance
{
NSString *path = [[NSBundle bundleForClass:self.class] resourcePath];
path = [path stringByAppendingPathComponent:@"HTML Standard.html"];
NSString *string = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self measureBlock:^{
HTMLTokenizer *tokenizer = [[HTMLTokenizer alloc] initWithString:string];
[tokenizer allObjects];
}];
}
@end