Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Boolean1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
- //
- #include "stdafx.h"
- //Or演算って遅いのか?
- //And演算やXor演算の倍近くかかるんだけど。
- //やってる処理は10000×10000、32bit画像の全画素に固定の32bitの値をAnd演算、Or演算、Xor演算するだけ。
- //環境
- //Win7 64bit VS2008
- //計測結果※clock()を使用
- //&= 69
- //|= 140
- //^= 68
- //せめて80~100くらいに押さえたい。
- #include <iostream>
- #include <Windows.h>
- #include <stdlib.h>
- #define N 10000
- #define X 0x3456789a // magic number
- static int matrix[N][N];
- struct foo {
- __int64 start, end, freq;
- HANDLE hprocess;
- DWORD oldclass;
- foo() : hprocess(GetCurrentProcess()), oldclass(GetPriorityClass(hprocess)) {
- Sleep(10);
- SetPriorityClass(hprocess, REALTIME_PRIORITY_CLASS);
- QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
- QueryPerformanceCounter((LARGE_INTEGER*)&start);
- }
- ~foo() {
- QueryPerformanceCounter((LARGE_INTEGER*)&end);
- SetPriorityClass(hprocess, oldclass);
- std::cout << (int)(end - start) << std::endl;
- }
- };
- int main()
- {
- srand(0);
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- matrix[i][j] = rand() * RAND_MAX + rand();
- std::cout << "AND arithmetic" << std::endl;
- {
- foo f;
- __asm {
- mov esi, 0
- LABEL1:
- mov edi, 0
- LABEL2:
- imul ecx, esi, N
- and dword ptr [ecx + edi + matrix], X
- inc edi
- cmp edi, N
- jl LABEL2
- inc esi
- cmp esi, N
- jl LABEL1
- }
- }
- srand(0);
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- matrix[i][j] = rand() * RAND_MAX + rand();
- std::cout << "OR arithmetic" << std::endl;
- {
- foo f;
- __asm {
- mov esi, 0
- LABEL3:
- mov edi, 0
- LABEL4:
- imul ecx, esi, N
- or dword ptr [ecx + edi + matrix], X
- inc edi
- cmp edi, N
- jl LABEL4
- inc esi
- cmp esi, N
- jl LABEL3
- }
- }
- srand(0);
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- matrix[i][j] = rand() * RAND_MAX + rand();
- std::cout << "XOR arithmetic" << std::endl;
- {
- foo f;
- __asm {
- mov esi, 0
- LABEL5:
- mov edi, 0
- LABEL6:
- imul ecx, esi, N
- xor dword ptr [ecx + edi + matrix], X
- inc edi
- cmp edi, N
- jl LABEL6
- inc esi
- cmp esi, N
- jl LABEL5
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement