[์•Œ๊ณ ๋ฆฌ์ฆ˜] ๊ณผ์ œ 2. 1000๋งŒ๊ฐœ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์ •๋ ฌ ์‹œ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„
/*
 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

๋ฐ˜์‘ํ˜•