mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 00:18:04 +00:00
del[net]: remove obsolete code
This commit is contained in:
1 parent
7c2615fcdf
commit
9f02e197c3
13 files changed
-16829
No files matched your search
@@ -1,21 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(cpp)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(PROJECT_MAIN cpp)
|
||||
|
||||
# main
|
||||
file(GLOB_RECURSE MAIN_SOURCES cppProtocol/*.c**)
|
||||
file(GLOB_RECURSE MAIN_HEADERS cppProtocol/*.h**)
|
||||
|
||||
# test
|
||||
file(GLOB_RECURSE TEST_SOURCES test/*.c**)
|
||||
file(GLOB_RECURSE TEST_HEADERS test/*.h**)
|
||||
|
||||
add_executable(${PROJECT_MAIN}
|
||||
main.cpp
|
||||
${TEST_SOURCES} ${TEST_HEADERS}
|
||||
${MAIN_SOURCES} ${MAIN_HEADERS})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "test/list_test.h"
|
||||
#include "test/byte_buffer_test.h"
|
||||
#include "test/serialization_test.h"
|
||||
#include "test/speed_test.h"
|
||||
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
try {
|
||||
list_test::list_all_test();
|
||||
byte_buffer_test::byte_buffer_all_test();
|
||||
serialization_test::protocol_all_test();
|
||||
|
||||
speed_test::parseObject();
|
||||
speed_test::singleThreadBenchmarks();
|
||||
} catch (string &e) {
|
||||
cout << e << endl;
|
||||
} catch (...) {
|
||||
cout << "unknown" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
#ifndef ZFOO_BYTE_BUFFER_TEST_H
|
||||
#define ZFOO_BYTE_BUFFER_TEST_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cppProtocol/ByteBuffer.h"
|
||||
|
||||
namespace byte_buffer_test {
|
||||
|
||||
using namespace zfoo;
|
||||
|
||||
void assert(bool flag) {
|
||||
if (!flag) {
|
||||
throw "exception happen";
|
||||
}
|
||||
}
|
||||
|
||||
void typeTest() {
|
||||
using namespace std;
|
||||
int32_t a = 0xFFFFFFFF;
|
||||
uint32_t b = 0xFFFFFFFF;
|
||||
assert(a == b);
|
||||
|
||||
b = a;
|
||||
assert(a == b);
|
||||
}
|
||||
|
||||
void boolTest(ByteBuffer &buffer) {
|
||||
bool value = true;
|
||||
buffer.writeBool(value);
|
||||
assert(buffer.readBool() == value);
|
||||
|
||||
value = false;
|
||||
buffer.writeBool(value);
|
||||
assert(buffer.readBool() == value);
|
||||
}
|
||||
|
||||
void byteTest(ByteBuffer &buffer) {
|
||||
int8_t values[] = {127, 0 - 128};
|
||||
for (auto value : values) {
|
||||
buffer.writeByte(value);
|
||||
assert(buffer.readByte() == value);
|
||||
}
|
||||
}
|
||||
|
||||
void bytesTest(ByteBuffer &buffer) {
|
||||
int8_t values[] = {127, 0 - 128};
|
||||
int length = sizeof(values) / sizeof(int8_t);
|
||||
buffer.writeBytes(values, length);
|
||||
int8_t *bytes = buffer.readBytes(length);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
assert(bytes[i] == values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void shortTest(ByteBuffer &buffer) {
|
||||
int16_t values[] = {-32768, -100, -2, -1, 0, 1, 2, 100, 32767};
|
||||
for (auto value : values) {
|
||||
buffer.writeShort(value);
|
||||
assert(buffer.readShort() == value);
|
||||
}
|
||||
}
|
||||
|
||||
void intTest(ByteBuffer &buffer) {
|
||||
int32_t values[] = {static_cast<int32_t>(0x80000000), -99999999, -9999, -100, -2, -1, 0, 1, 2, 100, 9999,
|
||||
99999999, 0x7fffffff};
|
||||
|
||||
for (auto value : values) {
|
||||
buffer.writeInt(value);
|
||||
assert(buffer.readInt() == value);
|
||||
}
|
||||
}
|
||||
|
||||
void longTest(ByteBuffer &buffer) {
|
||||
int64_t values[] = {static_cast<int64_t>(0x8000000000000000LL), -9999999999999999L, -9999999999999999L,
|
||||
-99999999, -9999, -100, -2, -1, 0, 1, 2, 100, 9999, 99999999, 9999999999999999L,
|
||||
0x7fffffffffffffffLL};
|
||||
|
||||
for (auto value : values) {
|
||||
buffer.writeLong(value);
|
||||
assert(buffer.readLong() == value);
|
||||
}
|
||||
}
|
||||
|
||||
void floatTest(ByteBuffer &buffer) {
|
||||
float values[] = {-12345678.12345678, -1234.5678, -100, -2, -1, 0, 1, 2, 100, 1234.5678, 12345678.12345678};
|
||||
for (auto value : values) {
|
||||
buffer.writeFloat(value);
|
||||
assert(std::abs(buffer.readFloat() - value) < 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
void doubleTest(ByteBuffer &buffer) {
|
||||
double values[] = {-1234.5678, -100, -2, -1, 0, 1, 2, 100, 1234.5678};
|
||||
for (auto value : values) {
|
||||
buffer.writeDouble(value);
|
||||
assert(std::abs(buffer.readDouble() - value) < 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
void stringTest(ByteBuffer &buffer) {
|
||||
using namespace std;
|
||||
string value = "hello world!";
|
||||
buffer.writeString(value);
|
||||
assert(buffer.readString().compare(value) == 0);
|
||||
}
|
||||
|
||||
|
||||
void byte_buffer_all_test() {
|
||||
using namespace std;
|
||||
|
||||
typeTest();
|
||||
|
||||
ByteBuffer buffer;
|
||||
assert(buffer.getCapacity() == DEFAULT_BUFFER_SIZE);
|
||||
assert(buffer.writerIndex() == 0);
|
||||
assert(buffer.readerIndex() == 0);
|
||||
|
||||
boolTest(buffer);
|
||||
byteTest(buffer);
|
||||
bytesTest(buffer);
|
||||
shortTest(buffer);
|
||||
intTest(buffer);
|
||||
floatTest(buffer);
|
||||
doubleTest(buffer);
|
||||
stringTest(buffer);
|
||||
}
|
||||
// void string_utf8_test(ByteBuffer &buffer) {
|
||||
// using namespace std;
|
||||
// string str = "我爱的人。。。..";
|
||||
// wstring utf8_str = buffer.string_to_utf8(str);
|
||||
// string str_origin = buffer.utf8_to_string(utf8_str);
|
||||
//
|
||||
// cout << str << endl;
|
||||
// cout << str_origin << endl;
|
||||
// std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
// std::string string = converter.to_bytes(utf8_str);
|
||||
// auto list = std::list<char>(string.begin(), string.end());
|
||||
// for (auto v : list) {
|
||||
// cout << std::to_string(v) << endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,135 +0,0 @@
|
||||
#ifndef ZFOO_LIST_H
|
||||
#define ZFOO_LIST_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace zfoo {
|
||||
|
||||
template<class T>
|
||||
class List {
|
||||
private:
|
||||
int max_list_size;
|
||||
int length;
|
||||
T *head;
|
||||
|
||||
private:
|
||||
void out() {
|
||||
T *p = head;
|
||||
for (int i = 0; i < length; i++, p++) {
|
||||
std::cout << *p << " "; //setw(sizeof(int))
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
List() {
|
||||
//默认构造函数,创建大小为100的空间
|
||||
max_list_size = 10;
|
||||
head = new T[max_list_size];
|
||||
length = 0;
|
||||
}
|
||||
|
||||
List(const List<T> &list) {
|
||||
max_list_size = list.max_list_size;
|
||||
length = list.length;
|
||||
head = new T[max_list_size];
|
||||
memcpy(head, list.head, max_list_size * sizeof(T));
|
||||
std::cout << "copy" << std::endl;
|
||||
}
|
||||
|
||||
List &operator=(const List<T> &list) {
|
||||
if (this == &list) {
|
||||
return *this;
|
||||
}
|
||||
if (head != nullptr) {
|
||||
delete[] head;
|
||||
}
|
||||
max_list_size = list.max_list_size;
|
||||
length = list.length;
|
||||
head = new T[max_list_size];
|
||||
memcpy(head, list.head, max_list_size * sizeof(T));
|
||||
std::cout << "operator" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
~List() {
|
||||
// 程序完成后,自动调用,释放数组空间
|
||||
if (head != nullptr) {
|
||||
delete[] head;
|
||||
std::cout << "deconstructor" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool isEmpty() const { return length == 0; }; //判断线性表是否为空
|
||||
int size() const { return length; }; //返回线性表长度
|
||||
|
||||
void add(T &x) {
|
||||
if (length >= max_list_size) {
|
||||
int newSize = max_list_size * 2;
|
||||
T *p = (T *) realloc(head, newSize * sizeof(T));
|
||||
max_list_size = newSize;
|
||||
head = p;
|
||||
}
|
||||
head[length++] = x;
|
||||
}
|
||||
|
||||
T *get(int index) { return (index >= length) ? nullptr : &head[index]; }
|
||||
|
||||
int indexOf(T &x) {// return -1 if x not in list.
|
||||
// return -1 if x not in list.
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (head[i] == x) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool remove(T &x) {
|
||||
int index = indexOf(x);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
// 开始移除
|
||||
length--;
|
||||
if (index == length) {
|
||||
return true;
|
||||
}
|
||||
memmove(&head[index], &head[index + 1], (length - index) * sizeof(T));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
friend std::ostream &operator<<(std::ostream &cout, List<T> &list) {
|
||||
list.out();
|
||||
return cout;
|
||||
}
|
||||
|
||||
bool operator<(const List &rhs) const {
|
||||
if (max_list_size < rhs.max_list_size)
|
||||
return true;
|
||||
if (rhs.max_list_size < max_list_size)
|
||||
return false;
|
||||
if (length < rhs.length)
|
||||
return true;
|
||||
if (rhs.length < length)
|
||||
return false;
|
||||
return head < rhs.head;
|
||||
}
|
||||
|
||||
bool operator>(const List &rhs) const {
|
||||
return rhs < *this;
|
||||
}
|
||||
|
||||
bool operator<=(const List &rhs) const {
|
||||
return !(rhs < *this);
|
||||
}
|
||||
|
||||
bool operator>=(const List &rhs) const {
|
||||
return !(*this < rhs);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,123 +0,0 @@
|
||||
#ifndef ZFOO_LIST_TEST_H
|
||||
#define ZFOO_LIST_TEST_H
|
||||
|
||||
#include "list.h"
|
||||
|
||||
namespace list_test {
|
||||
void assert(bool flag, std::string errorMessage) {
|
||||
if (!flag) {
|
||||
throw errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
void listCopyTest() {
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
List<int64_t> list;
|
||||
int64_t a = 1;
|
||||
int64_t b = 2;
|
||||
int64_t c = 3;
|
||||
list.add(a);
|
||||
list.add(b);
|
||||
list.add(c);
|
||||
|
||||
List<int64_t> newList = list;
|
||||
assert(newList.size() == 3, "listCopyTest size exception");
|
||||
assert(*newList.get(2) == 3, "listCopyTest get exception");
|
||||
assert(newList.indexOf(c) == 2, "listCopyTest indexOf exception");
|
||||
}
|
||||
|
||||
void listOperatorTest() {
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
List<int64_t> list;
|
||||
int64_t a = 1;
|
||||
int64_t b = 2;
|
||||
int64_t c = 3;
|
||||
list.add(a);
|
||||
list.add(b);
|
||||
list.add(c);
|
||||
|
||||
List<int64_t> newList;
|
||||
newList = list;
|
||||
assert(newList.size() == 3, "listOperatorTest size exception");
|
||||
assert(*newList.get(2) == 3, "listOperatorTest get exception");
|
||||
assert(newList.indexOf(c) == 2, "listOperatorTest indexOf exception");
|
||||
newList = newList;
|
||||
newList = newList;
|
||||
}
|
||||
|
||||
void listIntTest() {
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
List<int> list;
|
||||
assert(list.isEmpty(), "listIntTest isEmpty exception");
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
int c = 3;
|
||||
list.add(a);
|
||||
list.add(b);
|
||||
list.add(c);
|
||||
assert(list.size() == 3, "listIntTest size exception");
|
||||
assert(*list.get(1) == 2, "listIntTest get exception");
|
||||
assert(list.indexOf(b) == 1, "listIntTest indexOf exception");
|
||||
}
|
||||
|
||||
void listRemoveTest() {
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
List<int64_t> list;
|
||||
int64_t a = 1;
|
||||
int64_t b = 2;
|
||||
int64_t c = 3;
|
||||
int64_t d = 4;
|
||||
int64_t e = 5;
|
||||
int64_t f = 6;
|
||||
int64_t g = 7;
|
||||
list.add(a);
|
||||
list.add(b);
|
||||
list.add(c);
|
||||
list.add(d);
|
||||
list.add(e);
|
||||
list.add(f);
|
||||
|
||||
List<int64_t> list1 = list;
|
||||
List<int64_t> list2 = list;
|
||||
|
||||
assert(!list.remove(g), "listRemoveTest remove exception");
|
||||
assert(list.remove(f), "listRemoveTest remove exception");
|
||||
assert(*list.get(0) == a, "listRemoveTest get exception");
|
||||
assert(*list.get(4) == e, "listRemoveTest get exception");
|
||||
|
||||
list1.remove(a);
|
||||
assert(list1.get(5) == nullptr, "listRemoveTest get exception");
|
||||
assert(*list1.get(0) == b, "listRemoveTest get exception");
|
||||
assert(*list1.get(4) == f, "listRemoveTest get exception");
|
||||
|
||||
list2.remove(c);
|
||||
assert(*list2.get(0) == a, "listRemoveTest get exception");
|
||||
assert(*list2.get(4) == f, "listRemoveTest get exception");
|
||||
}
|
||||
|
||||
|
||||
void list_all_test() {
|
||||
using namespace std;
|
||||
try {
|
||||
listCopyTest();
|
||||
cout << "----------------------------------------------------------------------" << endl;
|
||||
listOperatorTest();
|
||||
cout << "----------------------------------------------------------------------" << endl;
|
||||
listIntTest();
|
||||
cout << "----------------------------------------------------------------------" << endl;
|
||||
listRemoveTest();
|
||||
cout << "----------------------------------------------------------------------" << endl;
|
||||
} catch (string &e) {
|
||||
cout << e << endl;
|
||||
} catch (...) {
|
||||
cout << "unknown" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,120 +0,0 @@
|
||||
#ifndef ZFOO_SERIALIZATION_TEST_H
|
||||
#define ZFOO_SERIALIZATION_TEST_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "cppProtocol/ProtocolManager.h"
|
||||
|
||||
|
||||
namespace serialization_test {
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
|
||||
void objectBTest() {
|
||||
ByteBuffer buffer;
|
||||
ObjectB objectB;
|
||||
objectB.flag = true;
|
||||
|
||||
write(buffer, &objectB);
|
||||
|
||||
ObjectB obj = *((ObjectB *) read(buffer));
|
||||
cout << "Hello, World!" << endl;
|
||||
}
|
||||
|
||||
void objectATest() {
|
||||
ByteBuffer buffer;
|
||||
ObjectA objectA;
|
||||
|
||||
ObjectB objectB;
|
||||
objectB.flag = true;
|
||||
|
||||
map<int32_t, string> map;
|
||||
map.insert(pair<int, string>(1, "a"));
|
||||
map.insert(pair<int, string>(2, "b"));
|
||||
map.insert(pair<int, string>(3, "c"));
|
||||
|
||||
objectA.a = 1;
|
||||
objectA.m = map;
|
||||
objectA.objectB = objectB;
|
||||
|
||||
write(buffer, &objectA);
|
||||
|
||||
ObjectA obj = *((ObjectA *) read(buffer));
|
||||
cout << "Hello, World!" << endl;
|
||||
}
|
||||
|
||||
|
||||
void normalObjectTest() {
|
||||
ByteBuffer buffer;
|
||||
|
||||
ObjectA objectA;
|
||||
ObjectB objectB;
|
||||
objectB.flag = true;
|
||||
|
||||
map<int32_t, string> map;
|
||||
map.insert(pair<int, string>(1, "a"));
|
||||
map.insert(pair<int, string>(2, "b"));
|
||||
map.insert(pair<int, string>(3, "c"));
|
||||
|
||||
objectA.a = 1;
|
||||
objectA.m = map;
|
||||
objectA.objectB = objectB;
|
||||
|
||||
NormalObject normalObject;
|
||||
normalObject.kk = objectA;
|
||||
normalObject.m = map;
|
||||
|
||||
write(buffer, &normalObject);
|
||||
NormalObject *p = (NormalObject *) read(buffer);
|
||||
cout << "Hello, World!" << endl;
|
||||
}
|
||||
|
||||
|
||||
void complexObjectTest() {
|
||||
// 读取二进制文件
|
||||
ifstream file("../../resources/ComplexObject.bytes", ios::out | ios::binary);
|
||||
unsigned char carray[10000];
|
||||
int length = 0;
|
||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
||||
length++;
|
||||
}
|
||||
file.close();
|
||||
|
||||
ByteBuffer buffer;
|
||||
buffer.writeBytes(reinterpret_cast<const int8_t *>(carray), length);
|
||||
ComplexObject obj = *((ComplexObject *) read(buffer));
|
||||
|
||||
ByteBuffer newBuffer;
|
||||
write(newBuffer, &obj);
|
||||
obj = *((ComplexObject *) read(newBuffer));
|
||||
cout << "Hello, World!" << endl;
|
||||
|
||||
for (int i = 0; i < 3000; ++i) {
|
||||
auto a = buffer.getByte(i);
|
||||
auto b = newBuffer.getByte(i);
|
||||
if (a != b) {
|
||||
cout << i << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void protocol_all_test() {
|
||||
try {
|
||||
initProtocol();
|
||||
objectBTest();
|
||||
objectATest();
|
||||
normalObjectTest();
|
||||
complexObjectTest();
|
||||
} catch (string &e) {
|
||||
cout << e << endl;
|
||||
} catch (...) {
|
||||
cout << "unknown" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
#ifndef ZFOO_SPEED_TEST_H
|
||||
#define ZFOO_SPEED_TEST_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "cppProtocol/ProtocolManager.h"
|
||||
|
||||
namespace speed_test {
|
||||
|
||||
using namespace zfoo;
|
||||
using namespace std;
|
||||
|
||||
SimpleObject *pSimpleObject = nullptr;
|
||||
NormalObject *pNormalObject = nullptr;
|
||||
ComplexObject *pComplexObject = nullptr;
|
||||
|
||||
int benchmark = 100000;
|
||||
|
||||
void parseObject() {
|
||||
// 读取二进制文件
|
||||
ifstream file("../../resources/ComplexObject.bytes", ios::out | ios::binary);
|
||||
unsigned char carray[10000];
|
||||
int length = 0;
|
||||
while (file.read((char *) &carray[length], sizeof(unsigned char))) {
|
||||
length++;
|
||||
}
|
||||
file.close();
|
||||
|
||||
ByteBuffer buffer;
|
||||
buffer.writeBytes(reinterpret_cast<const int8_t *>(carray), length);
|
||||
ComplexObject obj = *((ComplexObject *) read(buffer));
|
||||
|
||||
ByteBuffer newBuffer;
|
||||
write(newBuffer, &obj);
|
||||
pComplexObject = (ComplexObject *) read(newBuffer);
|
||||
|
||||
pSimpleObject = new SimpleObject();
|
||||
pSimpleObject->c = pComplexObject->c;
|
||||
pSimpleObject->g = pComplexObject->g;
|
||||
|
||||
pNormalObject = new NormalObject();
|
||||
pNormalObject->a = pComplexObject->a;
|
||||
pNormalObject->aaa = pComplexObject->aaa;
|
||||
pNormalObject->b = pComplexObject->b;
|
||||
pNormalObject->c = pComplexObject->c;
|
||||
pNormalObject->d = pComplexObject->d;
|
||||
pNormalObject->e = pComplexObject->e;
|
||||
pNormalObject->f = pComplexObject->f;
|
||||
pNormalObject->g = pComplexObject->g;
|
||||
pNormalObject->jj = pComplexObject->jj;
|
||||
pNormalObject->kk = pComplexObject->kk;
|
||||
pNormalObject->l = pComplexObject->l;
|
||||
pNormalObject->ll = {static_cast<int64_t>(0x8000000000000000LL), -9999999999999999L, -99999999L, -99L, 0L, 99L,
|
||||
99999999L, 9999999999999999L, 0x7fffffffffffffffLL};
|
||||
pNormalObject->lll.emplace_back(pComplexObject->kk);
|
||||
pNormalObject->lll.emplace_back(pComplexObject->kk);
|
||||
pNormalObject->lll.emplace_back(pComplexObject->kk);
|
||||
pNormalObject->llll = pComplexObject->llll;
|
||||
pNormalObject->m = pComplexObject->m;
|
||||
pNormalObject->mm = pComplexObject->mm;
|
||||
pNormalObject->s = pComplexObject->s;
|
||||
pNormalObject->ssss = pComplexObject->ssss;
|
||||
}
|
||||
|
||||
void zfooTest() {
|
||||
ByteBuffer buffer;
|
||||
|
||||
clock_t start = clock();
|
||||
for (int i = 0; i < benchmark; i++) {
|
||||
buffer.clear();
|
||||
write(buffer, pSimpleObject);
|
||||
auto packet = read(buffer);
|
||||
delete packet;
|
||||
}
|
||||
cout << "[zfoo] [简单对象][size:" << buffer.writerIndex() << "] [time:" << (clock() - start) << "]" << endl;
|
||||
|
||||
start = clock();
|
||||
for (int i = 0; i < benchmark; i++) {
|
||||
buffer.clear();
|
||||
write(buffer, pNormalObject);
|
||||
auto packet = read(buffer);
|
||||
delete packet;
|
||||
}
|
||||
cout << "[zfoo] [常规对象][size:" << buffer.writerIndex() << "] [time:" << (clock() - start) << "]" << endl;
|
||||
|
||||
start = clock();
|
||||
for (int i = 0; i < benchmark; i++) {
|
||||
buffer.clear();
|
||||
write(buffer, pComplexObject);
|
||||
auto packet = read(buffer);
|
||||
delete packet;
|
||||
}
|
||||
cout << "[zfoo] [复杂对象][size:" << buffer.writerIndex() << "] [time:" << (clock() - start) << "]" << endl;
|
||||
}
|
||||
|
||||
void singleThreadBenchmarks() {
|
||||
if (benchmark <= 0 || benchmark >= 1000000000) {
|
||||
return;
|
||||
}
|
||||
cout << "[单线程性能测试-->[benchmark:" << benchmark << "]]" << endl;
|
||||
zfooTest();
|
||||
benchmark = benchmark * 2;
|
||||
singleThreadBenchmarks();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2021 Viktor Kirilov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-6740
File diff suppressed because it is too large.
Load diff
-3284
File diff suppressed because it is too large.
Load diff
-2593
File diff suppressed because it is too large.
Load diff
-105
@@ -1,105 +0,0 @@
|
||||
// Formatting library for C++
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "format-inl.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
// DEPRECATED!
|
||||
template <typename T = void> struct basic_data {
|
||||
FMT_API static constexpr const char digits[100][2] = {
|
||||
{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
|
||||
{'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'},
|
||||
{'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'},
|
||||
{'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'},
|
||||
{'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'},
|
||||
{'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'},
|
||||
{'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'}, {'4', '0'}, {'4', '1'},
|
||||
{'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'},
|
||||
{'4', '8'}, {'4', '9'}, {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'},
|
||||
{'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'},
|
||||
{'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'},
|
||||
{'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'},
|
||||
{'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'},
|
||||
{'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'},
|
||||
{'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'},
|
||||
{'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, {'9', '5'},
|
||||
{'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
|
||||
FMT_API static constexpr const char hex_digits[] = "0123456789abcdef";
|
||||
FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '};
|
||||
FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1,
|
||||
0};
|
||||
FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1,
|
||||
0};
|
||||
FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+',
|
||||
0x1000000u | ' '};
|
||||
};
|
||||
|
||||
#ifdef FMT_SHARED
|
||||
// Required for -flto, -fivisibility=hidden and -shared to work
|
||||
extern template struct basic_data<void>;
|
||||
#endif
|
||||
|
||||
#if __cplusplus < 201703L
|
||||
// DEPRECATED! These are here only for ABI compatiblity.
|
||||
template <typename T> constexpr const char basic_data<T>::digits[][2];
|
||||
template <typename T> constexpr const char basic_data<T>::hex_digits[];
|
||||
template <typename T> constexpr const char basic_data<T>::signs[];
|
||||
template <typename T> constexpr const char basic_data<T>::left_padding_shifts[];
|
||||
template <typename T>
|
||||
constexpr const char basic_data<T>::right_padding_shifts[];
|
||||
template <typename T> constexpr const unsigned basic_data<T>::prefixes[];
|
||||
#endif
|
||||
|
||||
template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(
|
||||
float x) noexcept;
|
||||
template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(
|
||||
double x) noexcept;
|
||||
} // namespace detail
|
||||
|
||||
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
|
||||
int (*instantiate_format_float)(double, int, detail::float_specs,
|
||||
detail::buffer<char>&) = detail::format_float;
|
||||
|
||||
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
|
||||
template FMT_API detail::locale_ref::locale_ref(const std::locale& loc);
|
||||
template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
|
||||
#endif
|
||||
|
||||
// Explicit instantiations for char.
|
||||
|
||||
template FMT_API auto detail::thousands_sep_impl(locale_ref)
|
||||
-> thousands_sep_result<char>;
|
||||
template FMT_API char detail::decimal_point_impl(locale_ref);
|
||||
|
||||
template FMT_API void detail::buffer<char>::append(const char*, const char*);
|
||||
|
||||
// DEPRECATED!
|
||||
// There is no correspondent extern template in format.h because of
|
||||
// incompatibility between clang and gcc (#2377).
|
||||
template FMT_API void detail::vformat_to(
|
||||
detail::buffer<char>&, string_view,
|
||||
basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);
|
||||
|
||||
template FMT_API int detail::format_float(double, int, detail::float_specs,
|
||||
detail::buffer<char>&);
|
||||
template FMT_API int detail::format_float(long double, int, detail::float_specs,
|
||||
detail::buffer<char>&);
|
||||
|
||||
// Explicit instantiations for wchar_t.
|
||||
|
||||
template FMT_API auto detail::thousands_sep_impl(locale_ref)
|
||||
-> thousands_sep_result<wchar_t>;
|
||||
template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
|
||||
|
||||
template FMT_API void detail::buffer<wchar_t>::append(const wchar_t*,
|
||||
const wchar_t*);
|
||||
|
||||
template struct detail::basic_data<void>;
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
-3406
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user