RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* id_profile.cc 00002 Jeremy Barnes, 17 February 2012 00003 Copyright (c) 2012 Datacratic. All rights reserved. 00004 00005 */ 00006 00007 #include <iostream> 00008 #include "soa/types/id.h" 00009 #include "soa/types/date.h" 00010 00011 using namespace ML; 00012 using namespace std; 00013 using namespace Datacratic; 00014 00015 int hexToDec(int c) 00016 { 00017 int d = c & 0x1f; 00018 int i = (c & 0x60) >> 5; 00019 d += (i == 1) * -16; 00020 d += (i >= 2) * 9; 00021 bool h = isxdigit(c); 00022 return h * d - (!h); 00023 } 00024 00025 int hexToDec2(int c) 00026 { 00027 int v; 00028 00029 if (c >= '0' && c <= '9') 00030 v = c - '0'; 00031 else if (c >= 'a' && c <= 'f') 00032 v = c + 10 - 'a'; 00033 else if (c >= 'A' && c <= 'F') 00034 v = c + 10 - 'A'; 00035 else 00036 v = -1; 00037 00038 return v; 00039 } 00040 00041 static const signed char lookups[128] = { 00042 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00043 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00044 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00045 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 00046 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00047 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00048 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00049 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 00050 }; 00051 00052 inline int hexToDec3(int c) 00053 { 00054 return lookups[c & 0x1f]; 00055 } 00056 00057 void profile1() 00058 { 00059 Date before = Date::now(); 00060 00061 int n = 100000000; 00062 00063 for (unsigned i = 0; i < n; ++i) { 00064 (void)hexToDec(i % 127); 00065 } 00066 00067 Date after = Date::now(); 00068 double elapsed = after.secondsSince(before); 00069 00070 cerr << "processed " << n << " in " << elapsed << "s (" 00071 << 1.0 * n / elapsed << " per second)" << endl; 00072 } 00073 00074 void profile2() 00075 { 00076 Date before = Date::now(); 00077 00078 int n = 100000000; 00079 00080 for (unsigned i = 0; i < n; ++i) { 00081 (void)hexToDec2(i % 127); 00082 } 00083 00084 Date after = Date::now(); 00085 double elapsed = after.secondsSince(before); 00086 00087 cerr << "processed " << n << " in " << elapsed << "s (" 00088 << 1.0 * n / elapsed << " per second)" << endl; 00089 } 00090 00091 void profile3() 00092 { 00093 Date before = Date::now(); 00094 00095 int n = 100000000; 00096 00097 for (unsigned i = 0; i < n; ++i) { 00098 (void)hexToDec3(i % 127); 00099 } 00100 00101 Date after = Date::now(); 00102 double elapsed = after.secondsSince(before); 00103 00104 cerr << "processed " << n << " in " << elapsed << "s (" 00105 << 1.0 * n / elapsed << " per second)" << endl; 00106 } 00107 00108 int main(int argc, char ** argv) 00109 { 00110 //profile1(); 00111 //profile2(); 00112 //profile3(); 00113 00114 string ids[5] = { 00115 "2fa07c3c-1ac1-4001-15e8-42e6000003a1", 00116 "a78e802f-1ac1-4001-15e8-c6b0000003a0", 00117 "f8ece33b-1ac1-4001-15e8-42e6000003a1", 00118 "e46ead3d-1ac1-4001-15e8-ade2000003a1", 00119 "7081463e-1ac1-4001-15e8-01e8000003a0" 00120 }; 00121 00122 int nids = 5; 00123 00124 Date before = Date::now(); 00125 00126 int n = 10000000; 00127 00128 for (unsigned i = 0; i < n; ++i) { 00129 Id id(ids[i % nids]); 00130 //if (id.type != Id::UUID) 00131 // cerr << "bad type" << endl; 00132 //if (id.toString() != ids[i % nids]) 00133 // cerr << "bad parse" << endl; 00134 } 00135 00136 Date after = Date::now(); 00137 double elapsed = after.secondsSince(before); 00138 00139 cerr << "processed " << n << " in " << elapsed << "s (" 00140 << 1.0 * n / elapsed << " per second)" << endl; 00141 }