/*
2020-03-19 ์ฐํฌ์
์ฝ์
์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int buffer[10000000]; // ์ ์ญ ๋ณ์๋ก ๋ฃ์ด์ผ stack overflow๊ฐ ๋์ง ์์
void fileOpen() {
FILE *fp = fopen("d://algorithm/unsorted10000000.txt", "r");
int i = 0;
int tmp = 0;
if (fp == NULL) {
printf("ํ์ผ์ ์ด ์ ์์ต๋๋ค.\n");
}
while (fscanf(fp, "%d ", &tmp)!=EOF) {
buffer[i++] = tmp;
}
fclose(fp);
}
void insertSorting(int a) {
int size = 0;
int key,i,j;
for (i= 1; i < a; i++) {
key = buffer[i];
for (j = i - 1; j >= 0 && buffer[j] > key; j--) {
buffer[j + 1] = buffer[j];
}
buffer[j + 1] = key;
}
}
int calHash(int index_start, int index_end) {
int sum = 0;
for (int i = index_start; i < index_end+1; i++) {
sum += buffer[i] - (int)((int)(buffer[i] * pow(10, -5)) * pow(10, 5));
}
sum -= (int)((int)(sum * pow(10, -5)) * pow(10, 5));
return sum;
}
int main() {
printf("์๊ณ ๋ฆฌ์ฆ ๊ณผ์ 2\n");
printf(" ์ปดํจํฐ๊ณผํ๋ถ 2017920038 ์ฐํฌ์\n");
printf("ใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
ก\n");
time_t start, end;
int n = 10000000; // ๊ณ์ฐํ ์์ ๋ฒ์
/* ์๊ฐ ์ธก์ */
start = time(NULL);
struct tm tm = *localtime(&start);
printf("start: %d-%d-%d %d:%d:%d\n\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
printf("- ์ปดํจํฐ CPU : Intel(R) Core(TM) i7-7500U CPU\n");
printf("- ๋ฉ๋ชจ๋ฆฌ : 8GB\n");
/* ํ์ผ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ */
fileOpen();
/* ์ฝ์
์ ๋ ฌ */
insertSorting(n);
end = time(NULL);
printf("- ๋์์๊ฐ: %lfms\n", (double)(end - start));
/* hash ๊ณ์ฐ */
printf("- hash value: %d\n",calHash(4999999,5000099));
tm = *localtime(&end);
printf("end: %d-%d-%d %d:%d:%d\n\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0;
}
์์์๊ฐ
๋ฐ์ดํฐ๋ฅผ ํ์ผ์์ ๋ฐ์์ค๋๋ฐ 10์ด ์ ๋ ์์๋์๊ณ , ์ ์ฒด ์ฝ๋ ์ํ์๊ฐ์ 15097000ms, ์ฆ 251๋ถ์ด ์์๋์๋ค.
=> ์ฌ์ง์์๋ ๊ฒฐ๊ณผ๊ฐ ์๋ชป ์ถ๋ ฅ๋์์
hash ๊ฐ์ 500๋ง๋ฒ์งธ ์์ ~ 500๋ง 100๋ฒ์งธ ์์๊น์ง 101๊ฐ์ ํฉ์ ์๋ 5์๋ฆฌ๋ง ์ด์ฉํ์ฌ ํํํ ๊ฒ์ด๋ค.
์ปดํจํฐ ์ฌ์
์ปดํจํฐ CPU : Intel(R) Core(TM) i7-7500U CPU @ 2.70Ghz
๋ฉ๋ชจ๋ฆฌ : 8GB
๋ฐ์ํ
Comment