Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created August 20, 2012 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonsongithub/3405180 to your computer and use it in GitHub Desktop.
Save sonsongithub/3405180 to your computer and use it in GitHub Desktop.
Defulat pre-comiple header
#if TARGET_IPHONE_SIMULATOR
#import <objc/objc-runtime.h>
#else
#import <objc/runtime.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#pragma mark - for Debug
#ifdef _DEBUG
#define DNSLog(...) NSLog(__VA_ARGS__);
#define DNSLogMethod NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd));
#define DNSLogPoint(p) NSLog(@"%f,%f", p.x, p.y);
#define DNSLogSize(p) NSLog(@"%f,%f", p.width, p.height);
#define DNSLogRect(p) NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);
#else
#define DNSLog(...) //
#define DNSLogMethod //
#define DNSLogPoint(p) //
#define DNSLogSize(p) //
#define DNSLogRect(p) //
#endif
#pragma mark - for Profiling
static struct timeval _start, _end;
static void _tic() {
gettimeofday(&_start, NULL);
}
static void _toc() {
gettimeofday(&_end, NULL);
long int e_sec = _end.tv_sec * 1000000 + _end.tv_usec;
long int s_sec = _start.tv_sec * 1000000 + _start.tv_usec;
printf( "%9.4lf[ms]\n", (double)(e_sec - s_sec) / 1000.0);
}
static double _tocWithoutLog() {
gettimeofday(&_end, NULL);
long int e_sec = _end.tv_sec * 1000000 + _end.tv_usec;
long int s_sec = _start.tv_sec * 1000000 + _start.tv_usec;
return (double)(e_sec - s_sec) / 1000.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment