16,548
社区成员




#include <iostream>
#include <hash_map>
#include <string>
#include "stdlib.h"
#include "afx.h"
using namespace std;
using namespace stdext;
typedef CString TString;
//typedef string TString;
typedef TString *PString;
typedef hash_map<int, PString> HashMap_IS;
int main()
{
char cs[20];
_itoa_s(100, cs, sizeof(cs), 10);
cout << cs << endl;
HashMap_IS hm;
PString ps = new TString();
hm.insert(HashMap_IS::value_type(1, ps));
DWORD tick = GetTickCount();
for(int i = 2; i != 1000000; ++i)
{
_itoa_s(i, cs, sizeof(cs), 10);
ps = new TString(cs);
hm.insert(HashMap_IS::value_type(i, ps));
}
tick = GetTickCount() - tick;
_tprintf(_T("insert time = %d\n"), tick);
_tscanf_s(_T("test:"), &tick);
return 0;
}
// testCString.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "testCString.h"
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
void test1()
{
//CString s;
string s;
s = "123";
while(s.length() < 1024 * 1024 * 10)
{
s += s;
}
}
void testc()
{
CString s;
s = "123";
while(s.GetLength() < 1024 * 1024 * 10)
{
s += s;
}
}
void test()
{
for(int i = 1; i != 500; ++i)
{
test1();
//testc();
}
};
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
DWORD tick = GetTickCount();
test();
tick = GetTickCount() - tick;
CString s;
s.Format(_T("%d"), tick);
MessageBox(0, s.GetBuffer(), _T("test"), 0);
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
return nRetCode;
}