したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

1168774さん:2008/12/26(金) 21:07:49 ID:CENbthlg0
#include <windows.h>
#include <iostream>
#include <string>

const unsigned int count = 10000000;

int main(int argc, char **argv){
DWORD s = GetTickCount();

for(unsigned int i = 0; i < count; ++i){
char *p = new char;
delete p;
}

DWORD e = GetTickCount();

std::cout << e - s << std::endl;

unsigned int diff = e - s;

s = GetTickCount();

HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);

for(unsigned int i = 0; i < count; ++i){
WaitForSingleObject(hMutex, INFINITE);

ReleaseMutex(hMutex);
}

e = GetTickCount();

std::cout << e - s << std::endl;

unsigned int diff2 = e - s;

CloseHandle(hMutex);

CRITICAL_SECTION cs;

s = GetTickCount();

InitializeCriticalSection(&cs);

for(unsigned int i = 0; i < count; ++i){
EnterCriticalSection(&cs);

LeaveCriticalSection(&cs);
}

DeleteCriticalSection(&cs);

e = GetTickCount();

std::cout << e - s << std::endl;

unsigned int diff3 = e - s;

std::cout << (double)diff2 / (double)diff << std::endl;
std::cout << (double)diff3 / (double)diff << std::endl;

std::getline(std::cin, std::string());
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板