Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
179 lines (129 sloc) 3.79 KB
//
// ViewController.m
// Benchmark
//
// Created by ly on 4/19/16.
// Copyright © 2016 ly. All rights reserved.
//
#import "ViewController.h"
#import "TestModel.h"
static NSInteger count = 1000;
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self benchmark1];
[self benchmark2];
[self benchmark3];
[self benchmark4];
[self benchmark5];
[self benchmark11];
[self benchmark22];
[self benchmark33];
[self benchmark44];
[self benchmark55];
}
- (void)benchmark1
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
[m setValue:@"hello" forKey:@"_stringValue"];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setValue:@\"hello\" forKey:@\"_stringValue\"]: %f", endTime - startTime);
}
- (void)benchmark2
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
[m setValue:@"hello" forKey:@"stringValue"];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setValue:@\"hello\" forKey:@\"stringValue\"]: %f", endTime - startTime);
}
- (void)benchmark3
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
[m setStringValue:@"hello"];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setStringValue:@\"hello\"]: %f", endTime - startTime);
}
- (void)benchmark4
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
m->_stringValue = @"hello";
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"m->_stringValue = @\"hello\": %f", endTime - startTime);
}
- (void)benchmark5
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
m.stringValue = @"hello";
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"m.stringValue = @\"hello\": %f", endTime - startTime);
}
- (void)benchmark11
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
NSNumber *n = @(123);
for (NSInteger i = 0; i < count; i++) {
[m setValue:n forKey:@"_integerValue"];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setValue:n forKey:@\"_integerValue\"]: %f", endTime - startTime);
}
- (void)benchmark22
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
NSNumber *n = @(123);
for (NSInteger i = 0; i < count; i++) {
[m setValue:n forKey:@"integerValue"];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setValue:n forKey:@\"integerValue\"]: %f", endTime - startTime);
}
- (void)benchmark33
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
[m setIntegerValue:123];
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"[m setIntegerValue:123]: %f", endTime - startTime);
}
- (void)benchmark44
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
m->_integerValue = 123;
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"m->_integerValue = 123: %f", endTime - startTime);
}
- (void)benchmark55
{
CFTimeInterval startTime = CACurrentMediaTime();
TestModel *m = [TestModel new];
for (NSInteger i = 0; i < count; i++) {
m.integerValue = 123;
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"m.integerValue = 123: %f", endTime - startTime);
}
@end