-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add another bench on strings that works on vectors and basic operation
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "m-string.h" | ||
#include "common.h" | ||
|
||
void pass1(int n, string_t tab[n]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
string_init(tab[i]); | ||
} | ||
|
||
void pass2(int n, string_t tab[n]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
string_set(tab[i], "THIS IS IT"); | ||
} | ||
|
||
void pass3(string_t dst, int n, string_t tab[n]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
string_cat(dst, tab[i]); | ||
} | ||
|
||
void pass4(int n, string_t tab[n]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
string_clear(tab[i]); | ||
} | ||
|
||
int main(int argc, const char *argv[]) | ||
{ | ||
int n = argc >= 2 ? atoi(argv[1]): 200000000; | ||
unsigned long long t0 = cputime(); | ||
string_t *tab = (string_t *) malloc (n * sizeof(string_t)), dst; | ||
if (!tab) abort(); | ||
string_init(dst); | ||
pass1(n, tab); | ||
pass2(n, tab); | ||
pass3(dst, n, tab); | ||
pass4(n, tab); | ||
size_t s = string_size(dst); | ||
string_clear(dst); | ||
free(tab); | ||
unsigned long long t1 = cputime(); | ||
printf("BENCH STRING 3 / M*LIB: TIME=%llu ms LENGTH=%zu\n", t1-t0, s); | ||
exit(0); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <string> | ||
#include <iostream> | ||
|
||
#include "common.h" | ||
|
||
using namespace std; | ||
|
||
#define INIT(x) (new (&(x)) string()) | ||
#define CLEAR(x) ((&(x))->~string()) | ||
|
||
void pass1(int n, string tab[]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
INIT(tab[i]); | ||
} | ||
|
||
void pass2(int n, string tab[]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
tab[i] = "THIS IS IT"; | ||
} | ||
|
||
void pass3(string &dst, int n, string tab[]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
dst += tab[i]; | ||
} | ||
|
||
void pass4(int n, string tab[]) | ||
{ | ||
for(int i = 0; i < n; i++) | ||
CLEAR(tab[i]); | ||
} | ||
|
||
int main(int argc, const char *argv[]) | ||
{ | ||
int n = argc >= 2 ? atoi(argv[1]): 200000000; | ||
unsigned long long t0 = cputime(); | ||
string *tab = (string *) malloc (n * sizeof(string)), dst; | ||
if (!tab) abort(); | ||
pass1(n, tab); | ||
pass2(n, tab); | ||
pass3(dst, n, tab); | ||
pass4(n, tab); | ||
free(tab); | ||
unsigned long long t1 = cputime(); | ||
cout << "BENCH STRING 3 / STL: TIME=" << t1 - t0 << " ms LENGTH=" << dst.size() << endl; | ||
exit(0); | ||
} |