LINUX.ORG.RU

История изменений

Исправление kirk_johnson, (текущая версия) :

Блин, только что понял, что собиралось с -O2. Перемерял:

test1.c:

#include <stdio.h>
#include <string.h>

int main(){
        char buf[120];
        long long i;
        int x;
        fgets(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = strlen(buf);
        printf("%d\n", x);
        return 0;
}

test1.data:

P.S. þÔÏ ÚÎÁÞÉÔ <<ÔÏÒÍÏÚÑÔ>>? óÓÙÌËÉ ÎÁ ÂÅÎÞÍÁÒËÉ × ÓÔÕÄÉÀ.

test2.c:

#include <stdio.h>
#include <string.h>
#include <wchar.h>

int main(){
        wchar_t buf[120];
        long i;
        int x;
        fgetws(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = wcslen(buf);
        printf("%d\n", x);
        return 0;
}

test2.data:

P.S. Что значит <<тормозят>>? Ссылки на бенчмарки в студию.

Результаты:

$ cat test1.data | time ./test1 
60
./test1  48.63s user 0.01s system 99% cpu 48.645 total
$ cat test2.data | time ./test2 
7
./test2  45.37s user 0.00s system 99% cpu 45.372 total

P.S. Widecharacter тест закончился быстрее. Ололо.

Исправление kirk_johnson, :

Блин, только что понял, что собиралось с -O2. Перемерял:

test1.c:

#include <stdio.h>
#include <string.h>

int main(){
        char buf[120];
        long long i;
        int x;
        fgets(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = strlen(buf);
        printf("%d\n", x);
        return 0;
}

test1.data:

P.S. þÔÏ ÚÎÁÞÉÔ <<ÔÏÒÍÏÚÑÔ>>? óÓÙÌËÉ ÎÁ ÂÅÎÞÍÁÒËÉ × ÓÔÕÄÉÀ.

test2.c:

#include <stdio.h>
#include <string.h>
#include <wchar.h>

int main(){
        wchar_t buf[120];
        long i;
        int x;
        fgetws(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = wcslen(buf);
        printf("%d\n", x);
        return 0;
}

test2.data:

P.S. Что значит <<тормозят>>? Ссылки на бенчмарки в студию.

$ cat test1.data | time ./test1 
60
./test1  48.63s user 0.01s system 99% cpu 48.645 total
$ cat test2.data | time ./test2 
7
./test2  45.37s user 0.00s system 99% cpu 45.372 total

P.S. Widecharacter тест закончился быстрее. Ололо.

Исходная версия kirk_johnson, :

Блин, только что понял, что собиралось с -O2. Перемерял:

test1.c:

#include <stdio.h>
#include <string.h>

int main(){
        char buf[120];
        long long i;
        int x;
        fgets(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = strlen(buf);
        printf("%d\n", x);
        return 0;
}

test1.data:

P.S. þÔÏ ÚÎÁÞÉÔ <<ÔÏÒÍÏÚÑÔ>>? óÓÙÌËÉ ÎÁ ÂÅÎÞÍÁÒËÉ × ÓÔÕÄÉÀ.

test2.c:

#include <stdio.h>
#include <string.h>
#include <wchar.h>

int main(){
        wchar_t buf[120];
        long i;
        int x;
        fgetws(buf, 120, stdin);
        for (i = 0; i < 10000000000; i++) x = wcslen(buf);
        printf("%d\n", x);
        return 0;
}

test2.data:

P.S. Что значит <<тормозят>>? Ссылки на бенчмарки в студию.

$ cat test1.data | time ./test1 
60
./test1  48.63s user 0.01s system 99% cpu 48.645 total
$ cat test2.data | time ./test2 
7
./test2  45.37s user 0.00s system 99% cpu 45.372 total