JSON := OBJECT | ARRAY | NUMBER | STRING | BOOL | NULL
OBJECT := '{' KVS '}'
KVS := KEY ':' VALUE KVS2 | $
KVS2 := ',' KEY ':' VALUE KVS2 | $
KEY := NUMBER | STRING | BOOL
VALUE := JSON
ARRAY := '[' ELEMS ']'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ExprNode | |
{ | |
enum Type | |
{ | |
OPERATOR, | |
NUMBER | |
}; | |
enum OP | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
void int_to_str(unsigned int num, char* buffer, unsigned int size) | |
{ | |
static const char* digits = "0123456789"; | |
char* buf_ptr = buffer; | |
do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <cstring> | |
#define LOC(m, i, j, row_size) m[(i) * (row_size) + (j)] | |
void matrix_mul1(int* a, int* b, int* c, int size) | |
{ | |
int res = 0, i, j, k; | |
for (i = 0; i < size; ++i) | |
{ |
gperftools在结束的时候会有类似下面的输出:
PROFILE: interrupts/evictions/bytes = 123/1/1231231
在看了gperftools的代码之后,这几个数字的具体含义如下:
- interrupts代表收到信号的次数。由于gperftools是基于
setitimer
的,所以这个数字就是signal handler调用的次数。 - evictions代表把profile信息flush到磁盘的次数。在gperftools里面会有一个固定大小的buffer用来存储profile信息,而当这些信息超出大小的时候,会flush一部分信息到磁盘。
- bytes表示profile输出文件的大小。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use the following command to compile, -O2 is necessary | |
// g++ test_builtin_expect_asm.cpp -O2 -S -o test_builtin_expect_asm.S | |
// You can see that the branch expected will not jump. | |
#include <cstdlib> | |
#include <cstring> | |
#include <cstdio> | |
#define likely(x) __builtin_expect(!!(x), 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://stackoverflow.com/a/12261808/1208658 | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
template<typename T> | |
struct CalcDims | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef HAVE_BUILTIN_EXPECT | |
#define LIKELY(x) __builtin_expect(!!(x), 1) | |
#define UNLIKELY(x) __builtin_expect(!!(x), 0) | |
#else | |
#define LIKELY(x) (x) | |
#define UNLIKELY(x) (x) | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/time.h> | |
#include <sstream> | |
#include <iostream> | |
#include <string> | |
#include <wx/string.h> | |
#include <boost/format.hpp> | |
#include <boost/lexical_cast.hpp> | |
using namespace std; |