Optimized: C++ Compilation, ~10x speedup
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
debug:
|
||||
g++ -g3 -O0 server/server.cpp server/table.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||
g++ -g3 -O0 server/server.cpp server/io.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||
|
||||
test:
|
||||
g++ --std=c++1z -g3 -O0 server.cpp table.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||
g++ --std=c++1z -g3 -O0 server.cpp io.cpp -o a.out -Wall -Wextra -Wpedantic -lpthread
|
||||
|
||||
|
||||
+6
-7
@@ -1,29 +1,28 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <vector_type>
|
||||
#include <utility>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
class GC {
|
||||
template<class T>
|
||||
using vector = std::vector<T>;
|
||||
using vector = vector_type<T>;
|
||||
template<class ...T>
|
||||
using tuple = std::tuple<T...>;
|
||||
size_t current_size, max_size, interval, forced_clean;
|
||||
bool running, alive;
|
||||
// ptr, dealloc, ref, sz
|
||||
vector<tuple<void*, void (*)(void*), uint32_t, uint32_t>> q;
|
||||
vector<tuple<void*, void (*)(void*)>> q;
|
||||
std::thread handle;
|
||||
void gc()
|
||||
{
|
||||
|
||||
}
|
||||
template <class T>
|
||||
void reg(T* v, uint32_t ref, uint32_t sz,
|
||||
void(*f)(void*) = [](void* v) {delete[] ((T*)v); }) {
|
||||
void reg(void* v, uint32_t ref, uint32_t sz,
|
||||
void(*f)(void*) = [](void* v) {free (v); }) {
|
||||
current_size += sz;
|
||||
if (current_size > max_size)
|
||||
gc();
|
||||
q.push_back({ v, f, ref, sz });
|
||||
q.push_back({ v, f });
|
||||
}
|
||||
void daemon() {
|
||||
using namespace std::chrono;
|
||||
|
||||
+86
-1
@@ -8,4 +8,89 @@ void setgbuf(char* buf){
|
||||
gbuf = b;
|
||||
else
|
||||
gbuf = buf;
|
||||
}
|
||||
}
|
||||
|
||||
#include "table.h"
|
||||
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_int128str(v, s+40)<< delimiter;
|
||||
}
|
||||
template <>
|
||||
void print<__uint128_t>(const __uint128_t&v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_uint128str(v, s+40) << delimiter;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <>
|
||||
void print<bool>(const bool&v, const char* delimiter){
|
||||
std::cout<< (v?"true":"false") << delimiter;
|
||||
}
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
namespace types {
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
string date_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
tm;
|
||||
time_t;
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
}
|
||||
string time_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
}
|
||||
}
|
||||
|
||||
#include "utils.h"
|
||||
#include <random>
|
||||
using std::string;
|
||||
string base62uuid(int l = 8) {
|
||||
using namespace std;
|
||||
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
|
||||
static uniform_int_distribution<uint64_t> u(0x10000, 0xfffff);
|
||||
uint64_t uuid = (u(engine) << 32ull) + (chrono::system_clock::now().time_since_epoch().count() & 0xffffffff);
|
||||
printf("%p\n", uuid);
|
||||
string ret;
|
||||
while (uuid && l-- >= 0) {
|
||||
ret = string("") + base62alp[uuid % 62] + ret;
|
||||
uuid /= 62;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<typename _Ty>
|
||||
inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
|
||||
{
|
||||
n = n > size ? size : n;
|
||||
std::cout << '(';
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (; i < n - 1; ++i)
|
||||
std::cout << this->operator[](i) << sep;
|
||||
std::cout << this->operator[](i);
|
||||
}
|
||||
std::cout << ')';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "libaquery.h"
|
||||
#include "aggregations.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "monetdb_conn.h"
|
||||
#include "monetdbe.h"
|
||||
#include "threading.h"
|
||||
#include "../csv.h"
|
||||
#ifdef _WIN32
|
||||
#include "winhelper.h"
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
+7
-6
@@ -1,7 +1,6 @@
|
||||
#include "../csv.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
//#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "libaquery.h"
|
||||
@@ -69,14 +68,17 @@ __AQEXPORT__(bool) have_hge(){
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
Context::Context() {
|
||||
current.memory_map = new std::unordered_map<void*, deallocator_t>;
|
||||
init_session();
|
||||
}
|
||||
|
||||
Context::~Context() {
|
||||
auto memmap = (std::unordered_map<void*, deallocator_t>*) this->current.memory_map;
|
||||
delete memmap;
|
||||
}
|
||||
|
||||
void Context::init_session(){
|
||||
if (log_level == LOG_INFO){
|
||||
memset(&(this->current.stats), 0, sizeof(Session::Statistic));
|
||||
@@ -226,7 +228,7 @@ int dll_main(int argc, char** argv, Context* cxt){
|
||||
|
||||
int launcher(int argc, char** argv){
|
||||
std::string str = " ";
|
||||
for (int i = 0; i < argc; i++){
|
||||
for (int i = 1; i < argc; i++){
|
||||
str += argv[i];
|
||||
str += " ";
|
||||
}
|
||||
@@ -235,6 +237,9 @@ int launcher(int argc, char** argv){
|
||||
}
|
||||
|
||||
extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
|
||||
#ifdef __AQ_BUILD_LAUNCHER__
|
||||
return launcher(argc, argv);
|
||||
#endif
|
||||
puts("running");
|
||||
Context* cxt = new Context();
|
||||
cxt->log("%d %s\n", argc, argv[1]);
|
||||
@@ -248,11 +253,7 @@ extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
|
||||
if (argc < 0)
|
||||
return dll_main(argc, argv, cxt);
|
||||
else if (argc <= 1)
|
||||
#ifdef __AQ__TESTING__
|
||||
return test_main();
|
||||
#else
|
||||
return launcher(argc, argv);
|
||||
#endif
|
||||
else
|
||||
shmname = argv[1];
|
||||
SharedMemory shm = SharedMemory(shmname);
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
<ItemGroup>
|
||||
<Media Include="..\out.cpp" />
|
||||
<ClCompile Include="monetdb_conn.cpp" />
|
||||
<ClCompile Include="table.cpp" />
|
||||
<ClCompile Include="io.cpp" />
|
||||
<ClCompile Include="server.cpp" />
|
||||
<ClCompile Include="types.cpp" />
|
||||
<ClCompile Include="utils.cpp" />
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "table.h"
|
||||
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
template <>
|
||||
void print<__int128_t>(const __int128_t& v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_int128str(v, s+40)<< delimiter;
|
||||
}
|
||||
template <>
|
||||
void print<__uint128_t>(const __uint128_t&v, const char* delimiter){
|
||||
char s[41];
|
||||
s[40] = 0;
|
||||
std::cout<< get_uint128str(v, s+40) << delimiter;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __int128 & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, __uint128_t & v)
|
||||
{
|
||||
print(v);
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <>
|
||||
void print<bool>(const bool&v, const char* delimiter){
|
||||
std::cout<< (v?"true":"false") << delimiter;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "vector_type.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "io.h"
|
||||
#undef ERROR
|
||||
template <typename T>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "types.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
namespace types {
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
string date_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
tm;
|
||||
time_t;
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
}
|
||||
string time_t::toString() const {
|
||||
uint32_t curr_v = val;
|
||||
|
||||
return string() + string("/") + string() + string("/") + string();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#ifndef _TYPES_H
|
||||
#define _TYPES_H
|
||||
#include <typeinfo>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "utils.h"
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
using std::string;
|
||||
string base62uuid(int l = 8) {
|
||||
using namespace std;
|
||||
constexpr static const char* base62alp = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static mt19937_64 engine(chrono::system_clock::now().time_since_epoch().count());
|
||||
static uniform_int_distribution<uint64_t> u(0x10000, 0xfffff);
|
||||
uint64_t uuid = (u(engine) << 32ull) + (chrono::system_clock::now().time_since_epoch().count() & 0xffffffff);
|
||||
printf("%p\n", uuid);
|
||||
string ret;
|
||||
while (uuid && l-- >= 0) {
|
||||
ret = string("") + base62alp[uuid % 62] + ret;
|
||||
uuid /= 62;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "vector_type.hpp"
|
||||
#include <iostream>
|
||||
template<typename _Ty>
|
||||
inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
|
||||
{
|
||||
n = n > size ? size : n;
|
||||
std::cout << '(';
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (; i < n - 1; ++i)
|
||||
std::cout << this->operator[](i) << sep;
|
||||
std::cout << this->operator[](i);
|
||||
}
|
||||
std::cout << ')';
|
||||
}
|
||||
@@ -10,12 +10,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
#include <stdarg.h>
|
||||
#include <limits>
|
||||
#include <deque>
|
||||
#include "types.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
Reference in New Issue
Block a user