|
Boost : |
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-02-02 14:10:43
For those who think that the challenge of C++ memory management
means we should just use Java (this is with Sun's latest JIT) ...
D:\greg\Boost>java TestPtr 1000000
fill array: 5281
sort array: 18672
D:\greg\Boost>test_ptr 1000000
testing 1000000 shared_ptr<int>
fill vector: 1859
sort vector: 1812
D:\greg\Boost>test_ptr 1000000
testing 1000000 int*
fill vector: 843
sort vector: 422
////////////////////////////////////////////////////////////////////////////////
import java.util.*;
class TestPtr {
public static void main(String args[]) {
final int N = Integer.parseInt(args[0]);
Random random = new Random();
long start = System.currentTimeMillis();
Integer[] array = new Integer[N];
for (int i = 0; i < N; i++ )
array[i] = new Integer(random.nextInt());
System.out.println("fill array: " + (System.currentTimeMillis() - start));
start = System.currentTimeMillis();
Arrays.sort(array);
System.out.println("sort array: " + (System.currentTimeMillis() - start));
}
}
////////////////////////////////////////////////////////////////////////////////
#include <vector>
#include <algorithm>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <boost/smart_ptr.hpp>
using namespace std;
using namespace boost;
int main(int argc, char** argv) {
const int N = atoi(argv[1]);
#ifdef RAW
typedef int* ptr_int;
printf("testing %d int* \n", N);
#else
typedef shared_ptr<int> ptr_int;
printf("testing %d shared_ptr<int>\n", N);
#endif
{ clock_t start = clock();
vector<ptr_int> container(N);;
for (int i = 0; i < N; i++ )
container[i] = ptr_int(new int(rand()));
printf("fill vector: %ld\n",
((long)clock() - start)*1000/CLOCKS_PER_SEC);
start = clock();
sort(container.begin(), container.end());
printf("sort vector: %ld\n",
((long)clock() - start)*1000/CLOCKS_PER_SEC);
}
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk