mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
.benchmarks
git-svn-id: svn://ultimatepp.org/upp/trunk@4748 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
51ca18bbbd
commit
a1aff03eaa
5 changed files with 296 additions and 293 deletions
|
|
@ -12,7 +12,7 @@ public:
|
|||
CONSOLE_APP_MAIN
|
||||
{
|
||||
RTIMING("NewDelete");
|
||||
for (int i=0; i<=10000000; i++) {
|
||||
for (int i=0; i<=100000000; i++) {
|
||||
Test *test = new Test(i);
|
||||
delete test;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
NewDelete.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "",
|
||||
"" = "USEMALLOC";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
NewDelete.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "",
|
||||
"" = "USEMALLOC",
|
||||
"" = "MT";
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ file
|
|||
data.txt;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2 MT",
|
||||
"" = "SSE2";
|
||||
"" = "SSE2 MT SVO_VALUE",
|
||||
"" = "SSE2 SVO_VALUE";
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,7 @@ mainconfig
|
|||
"" = "USEMALLOC",
|
||||
"" = "MT",
|
||||
"" = "USEMALLOC MT",
|
||||
"" = "HEAPSTAT";
|
||||
"" = "HEAPSTAT",
|
||||
"" = "SVO_VALUE MT",
|
||||
"" = "SVO_VALUE";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,279 +1,279 @@
|
|||
#define NDEBUG
|
||||
#define _SECURE_SCL 0
|
||||
|
||||
#include <Core/Core.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#define TEST_HASHMAP
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
|
||||
#ifdef COMPILER_GCC
|
||||
#include <tr1/unordered_map>
|
||||
#else
|
||||
#include <hash_map>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace Upp;
|
||||
|
||||
#ifndef _DEBUG
|
||||
#define NO_OUTPUT // for benchmark purposes, output is omitted
|
||||
#endif
|
||||
|
||||
void BenchNTL(const char *file) {
|
||||
FileIn in(file);
|
||||
if (!in) {
|
||||
std::cout << "Cannot open input file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
VectorMap<String, Vector<int> > map;
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.Get();
|
||||
if(c < 0) break;
|
||||
if(IsAlpha(c) || c == '_') {
|
||||
String id;
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '_')) {
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
}
|
||||
map.GetAdd(id).Add(line);
|
||||
}
|
||||
else
|
||||
if(IsDigit(c))
|
||||
do c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
Vector<int> order = GetSortOrder(map.GetKeys());
|
||||
#ifndef NO_OUTPUT
|
||||
for(int i = 0; i < order.GetCount(); i++) {
|
||||
std::cout << ~map.GetKey(order[i]) << ": ";
|
||||
const Vector<int>& l = map[order[i]];
|
||||
for(int i = 0; i < l.GetCount(); i++) {
|
||||
if(i) std::cout << ", ";
|
||||
std::cout << l[i];
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SimpleValueOrder(const Value& a, const Value& b)
|
||||
{
|
||||
return AsString(a) < AsString(b);
|
||||
}
|
||||
|
||||
void BenchValueMap(const char *file) {
|
||||
FileIn in(file);
|
||||
if (!in) {
|
||||
std::cout << "Cannot open input file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
ValueMap map;
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.Get();
|
||||
if(c < 0) break;
|
||||
if(IsAlpha(c) || c == '_') {
|
||||
String id;
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '_')) {
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
}
|
||||
#ifdef SVO_VALUE
|
||||
ValueArray va = map.GetAndClear(id);
|
||||
#else
|
||||
ValueArray va = map[id];
|
||||
#endif
|
||||
va.Add(line);
|
||||
map.Set(id, va);
|
||||
}
|
||||
else
|
||||
if(IsDigit(c))
|
||||
do c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
Vector<int> order = GetSortOrder(map.GetKeys(), SimpleValueOrder);
|
||||
#ifndef NO_OUTPUT
|
||||
for(int i = 0; i < order.GetCount(); i++) {
|
||||
std::cout << ~(String)(map.GetKeys()[order[i]]) << ": ";
|
||||
ValueArray l = map.GetValues()[order[i]];
|
||||
for(int i = 0; i < l.GetCount(); i++) {
|
||||
if(i) std::cout << ", ";
|
||||
std::cout << (int)l[i];
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
void BenchSTL(Container& imap, const char *file) {
|
||||
std::ifstream in(file);
|
||||
if (!in) {
|
||||
std::cout << "Cannot open input file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.get();
|
||||
if(c == EOF) break;
|
||||
if(isalpha(c) || c == '_') {
|
||||
string id;
|
||||
id += c;
|
||||
c = in.get();
|
||||
while(c != EOF && (isalnum(c) || c == '_')) {
|
||||
id += c;
|
||||
c = in.get();
|
||||
}
|
||||
imap[id].push_back(line);
|
||||
}
|
||||
else
|
||||
if(isdigit(c))
|
||||
do c = in.get();
|
||||
while(c != EOF && (isalnum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMap(const char *file)
|
||||
{
|
||||
map< string, vector<int> > imap;
|
||||
BenchSTL(imap, file);
|
||||
#ifndef NO_OUTPUT
|
||||
map< std::string, vector<int> >::const_iterator e = imap.end();
|
||||
for(map< std::string, vector<int> >::const_iterator i = imap.begin(); i != e; i++) {
|
||||
std::cout << i->first << ": ";
|
||||
vector<int>::const_iterator e = i->second.end();
|
||||
vector<int>::const_iterator b = i->second.begin();
|
||||
for(vector<int>::const_iterator j = b; j != e; j++) {
|
||||
if(j != b) std::cout << ", ";
|
||||
std::cout << *j;
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
|
||||
#ifdef COMPILER_GCC
|
||||
typedef std::tr1::unordered_map< string, vector<int> > HashMap;
|
||||
#else
|
||||
typedef stdext::hash_map< string, vector<int> > HashMap;
|
||||
#endif
|
||||
|
||||
inline bool h_less(const HashMap::value_type *a, const HashMap::value_type *b)
|
||||
{
|
||||
return a->first < b->first;
|
||||
}
|
||||
|
||||
void BenchHashMap(const char *file)
|
||||
{
|
||||
HashMap imap;
|
||||
BenchSTL(imap, file);
|
||||
vector< const HashMap::value_type * > order;
|
||||
for(HashMap::const_iterator i = imap.begin(); i != imap.end(); i++)
|
||||
order.push_back(&*i);
|
||||
sort(order.begin(), order.end(), h_less);
|
||||
|
||||
#ifndef NO_OUTPUT
|
||||
vector< const HashMap::value_type * >::const_iterator e = order.end();
|
||||
for(vector< const HashMap::value_type * >::const_iterator i = order.begin(); i != e; i++) {
|
||||
std::cout << (*i)->first << ": ";
|
||||
vector<int>::const_iterator e = (*i)->second.end();
|
||||
vector<int>::const_iterator b = (*i)->second.begin();
|
||||
for(vector<int>::const_iterator j = b; j != e; j++) {
|
||||
if(j != b) std::cout << ", ";
|
||||
std::cout << *j;
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define N 1
|
||||
#else
|
||||
#define N 10000
|
||||
#endif
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
String fn;
|
||||
int argc = CommandLine().GetCount();
|
||||
const Vector<String>& argv = CommandLine();
|
||||
if(argc < 1)
|
||||
fn = GetDataFile("main.cpp");
|
||||
else
|
||||
fn = argv[0];
|
||||
|
||||
BenchValueMap(fn);
|
||||
cout << "===========================\n";
|
||||
BenchNTL(fn); // first run to cache the file
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
{
|
||||
BenchHashMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchHashMap(fn);
|
||||
cout << "STL hash_map time: " << tm.Elapsed() << " ms \n";
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
BenchMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchMap(fn);
|
||||
cout << "STL map time: " << tm.Elapsed() << " ms \n";
|
||||
}
|
||||
|
||||
{
|
||||
BenchNTL(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchNTL(fn);
|
||||
cout << "NTL time: " << tm.Elapsed() << " ms\n";
|
||||
}
|
||||
|
||||
{
|
||||
BenchValueMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchValueMap(fn);
|
||||
cout << "ValueMap time: " << tm.Elapsed() << " ms\n";
|
||||
}
|
||||
}
|
||||
#define NDEBUG
|
||||
#define _SECURE_SCL 0
|
||||
|
||||
#include <Core/Core.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#define TEST_HASHMAP
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
|
||||
#ifdef COMPILER_GCC
|
||||
#include <tr1/unordered_map>
|
||||
#else
|
||||
#include <hash_map>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace Upp;
|
||||
|
||||
#ifndef _DEBUG
|
||||
#define NO_OUTPUT // for benchmark purposes, output is omitted
|
||||
#endif
|
||||
|
||||
void BenchNTL(const char *file) {
|
||||
FileIn in(file);
|
||||
if (!in) {
|
||||
RLOG("Cannot open input file.");
|
||||
return;
|
||||
}
|
||||
|
||||
VectorMap<String, Vector<int> > map;
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.Get();
|
||||
if(c < 0) break;
|
||||
if(IsAlpha(c) || c == '_') {
|
||||
String id;
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '_')) {
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
}
|
||||
map.GetAdd(id).Add(line);
|
||||
}
|
||||
else
|
||||
if(IsDigit(c))
|
||||
do c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
Vector<int> order = GetSortOrder(map.GetKeys());
|
||||
#ifndef NO_OUTPUT
|
||||
for(int i = 0; i < order.GetCount(); i++) {
|
||||
std::cout << ~map.GetKey(order[i]) << ": ";
|
||||
const Vector<int>& l = map[order[i]];
|
||||
for(int i = 0; i < l.GetCount(); i++) {
|
||||
if(i) std::cout << ", ";
|
||||
std::cout << l[i];
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SimpleValueOrder(const Value& a, const Value& b)
|
||||
{
|
||||
return AsString(a) < AsString(b);
|
||||
}
|
||||
|
||||
void BenchValueMap(const char *file) {
|
||||
FileIn in(file);
|
||||
if (!in) {
|
||||
RLOG("Cannot open input file.");
|
||||
return;
|
||||
}
|
||||
|
||||
ValueMap map;
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.Get();
|
||||
if(c < 0) break;
|
||||
if(IsAlpha(c) || c == '_') {
|
||||
String id;
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '_')) {
|
||||
id.Cat(c);
|
||||
c = in.Get();
|
||||
}
|
||||
#ifdef SVO_VALUE
|
||||
ValueArray va = map.GetAndClear(id);
|
||||
#else
|
||||
ValueArray va = map[id];
|
||||
#endif
|
||||
va.Add(line);
|
||||
map.Set(id, va);
|
||||
}
|
||||
else
|
||||
if(IsDigit(c))
|
||||
do c = in.Get();
|
||||
while(c >= 0 && (IsAlNum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
Vector<int> order = GetSortOrder(map.GetKeys(), SimpleValueOrder);
|
||||
#ifndef NO_OUTPUT
|
||||
for(int i = 0; i < order.GetCount(); i++) {
|
||||
std::cout << ~(String)(map.GetKeys()[order[i]]) << ": ";
|
||||
ValueArray l = map.GetValues()[order[i]];
|
||||
for(int i = 0; i < l.GetCount(); i++) {
|
||||
if(i) std::cout << ", ";
|
||||
std::cout << (int)l[i];
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
void BenchSTL(Container& imap, const char *file) {
|
||||
std::ifstream in(file);
|
||||
if (!in) {
|
||||
RLOG("Cannot open input file.");
|
||||
return;
|
||||
}
|
||||
|
||||
int line = 1;
|
||||
|
||||
for(;;) {
|
||||
int c = in.get();
|
||||
if(c == EOF) break;
|
||||
if(isalpha(c) || c == '_') {
|
||||
string id;
|
||||
id += c;
|
||||
c = in.get();
|
||||
while(c != EOF && (isalnum(c) || c == '_')) {
|
||||
id += c;
|
||||
c = in.get();
|
||||
}
|
||||
imap[id].push_back(line);
|
||||
}
|
||||
else
|
||||
if(isdigit(c))
|
||||
do c = in.get();
|
||||
while(c != EOF && (isalnum(c) || c == '.'));
|
||||
if(c == '\n')
|
||||
++line;
|
||||
}
|
||||
}
|
||||
|
||||
void BenchMap(const char *file)
|
||||
{
|
||||
map< string, vector<int> > imap;
|
||||
BenchSTL(imap, file);
|
||||
#ifndef NO_OUTPUT
|
||||
map< std::string, vector<int> >::const_iterator e = imap.end();
|
||||
for(map< std::string, vector<int> >::const_iterator i = imap.begin(); i != e; i++) {
|
||||
std::cout << i->first << ": ";
|
||||
vector<int>::const_iterator e = i->second.end();
|
||||
vector<int>::const_iterator b = i->second.begin();
|
||||
for(vector<int>::const_iterator j = b; j != e; j++) {
|
||||
if(j != b) std::cout << ", ";
|
||||
std::cout << *j;
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
|
||||
#ifdef COMPILER_GCC
|
||||
typedef std::tr1::unordered_map< string, vector<int> > HashMap;
|
||||
#else
|
||||
typedef stdext::hash_map< string, vector<int> > HashMap;
|
||||
#endif
|
||||
|
||||
inline bool h_less(const HashMap::value_type *a, const HashMap::value_type *b)
|
||||
{
|
||||
return a->first < b->first;
|
||||
}
|
||||
|
||||
void BenchHashMap(const char *file)
|
||||
{
|
||||
HashMap imap;
|
||||
BenchSTL(imap, file);
|
||||
vector< const HashMap::value_type * > order;
|
||||
for(HashMap::const_iterator i = imap.begin(); i != imap.end(); i++)
|
||||
order.push_back(&*i);
|
||||
sort(order.begin(), order.end(), h_less);
|
||||
|
||||
#ifndef NO_OUTPUT
|
||||
vector< const HashMap::value_type * >::const_iterator e = order.end();
|
||||
for(vector< const HashMap::value_type * >::const_iterator i = order.begin(); i != e; i++) {
|
||||
std::cout << (*i)->first << ": ";
|
||||
vector<int>::const_iterator e = (*i)->second.end();
|
||||
vector<int>::const_iterator b = (*i)->second.begin();
|
||||
for(vector<int>::const_iterator j = b; j != e; j++) {
|
||||
if(j != b) std::cout << ", ";
|
||||
std::cout << *j;
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define N 1
|
||||
#else
|
||||
#define N 10000
|
||||
#endif
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
String fn;
|
||||
int argc = CommandLine().GetCount();
|
||||
const Vector<String>& argv = CommandLine();
|
||||
if(argc < 1)
|
||||
fn = GetDataFile("main.cpp");
|
||||
else
|
||||
fn = argv[0];
|
||||
|
||||
BenchNTL(fn); // first run to cache the file
|
||||
|
||||
#ifdef TEST_HASHMAP
|
||||
{
|
||||
BenchHashMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchHashMap(fn);
|
||||
RLOG("STL hash_map time: " << tm.Elapsed() << " ms");
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
BenchMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchMap(fn);
|
||||
RLOG("STL map time: " << tm.Elapsed() << " ms");
|
||||
}
|
||||
|
||||
{
|
||||
BenchNTL(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchNTL(fn);
|
||||
RLOG("NTL time: " << tm.Elapsed() << " ms");
|
||||
}
|
||||
|
||||
{
|
||||
BenchValueMap(fn);
|
||||
TimeStop tm;
|
||||
for(int n = 0; n < N; n++)
|
||||
BenchValueMap(fn);
|
||||
RLOG("ValueMap time: " << tm.Elapsed() << " ms");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue