------------------------------MFC 코드 ----------------------------------------------------------
void CChildView::OnPaint()
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
unsigned int count=0;
CTime start=CTime::GetCurrentTime();
for(int i=0;i<1000;i++){
for(int j=0;j<1000;j++){
CBrush NewBrush(RGB(rand()%255,rand()%255,rand()%255));
dc.FillRect(CRect(i,j,i+50,j+50),&NewBrush);
count++;
}
}
CTime end=CTime::GetCurrentTime();
CTimeSpan t=end-start;
CString str=_T("");
str.Format(_T("%d초 소요, 그린 횟수 : %d"),t.GetSeconds(),count);
MessageBox(str);
}
package view;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class SpeedView extends JFrame{
boolean b=false;
Random r=new Random();
public SpeedView(){
super("SpeedTest");
setBounds(0,0,1000,1000);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
@Override
public void paint(Graphics g) {
super.paint(g);
int c=0;
int y=0;
long start=System.currentTimeMillis();
for(int i=0;i<1000;i++){
for(int j=0;j<1000;j++){
g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));
g.fillRect(i, j, 50, 50);
c++;
}
}
long end=System.currentTimeMillis();
String msg=(end - start)/1000 + "초 소요, 그린 횟수 : "+c;
if(b==false){
b=true;
JOptionPane.showMessageDialog(this, msg);
}
}
public static void main(String[] args) {
new SpeedView();
}
}
--------------------------WinAPI---------------------------------------------------------
#include <windows.h>
#include <time.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpszClass=TEXT("Class");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,NULL,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
int passtime;
TCHAR msg[128];
LARGE_INTEGER start, end, count;
static HBRUSH hBrush,oldBrush;
static RECT rt;
int cnt=0;
switch (iMessage) {
case WM_CREATE:
hWndMain=hWnd;
SetWindowPos(hWnd,NULL,0,0,1000,1000,SWP_NOZORDER);
srand( (unsigned int)(time(NULL)) );
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd, &ps);
QueryPerformanceFrequency(&count);
QueryPerformanceCounter(&start);
for(int i=0;i<1000;i++){
for(int j=0;j<1000;j++){
hBrush=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
oldBrush=(HBRUSH)SelectObject(hdc,hBrush);
rt.left=i;
rt.top=j;
rt.right=i+50;
rt.bottom=j+50;
FillRect(hdc,&rt,hBrush);
DeleteObject(SelectObject(hdc,oldBrush));
cnt++;
}
}
QueryPerformanceCounter(&end);
passtime = (end.QuadPart - start.QuadPart) / count.QuadPart ;
wsprintf(msg ,TEXT("%d초 소요, 그린 횟수 : %d"), passtime, cnt);
MessageBox(hWnd,msg,TEXT("WinAPI"),MB_OK);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.