Skip to content

Latest commit

 

History

History
238 lines (199 loc) · 16.3 KB

File metadata and controls

238 lines (199 loc) · 16.3 KB

Benchmark of self-made Unicode reader writen in C

Preambula

>/usr/sbin/system_profiler SPHardwareDataType

Hardware:
    Hardware Overview:
      Model Name: MacBook Pro
      Model Identifier: MacBookPro14,3
      Processor Name: Quad-Core Intel Core i7
      Processor Speed: 2,8 GHz
      Number of Processors: 1
      Total Number of Cores: 4
      L2 Cache (per Core): 256 KB
      L3 Cache: 6 MB
      Hyper-Threading Technology: Enabled
      Memory: 16 GB

C benchmark functions:

const char *mix = "OoZe9ab8 \07Eef9hooj \nweiph7iD\r OoMai8ra FaHeaf7g ingie2Ah\t Wei4abah uL3pheog тхеед4Бе еЦхамаЪ0 Привет, 😀ອັກສອນລາວ World";
__attribute__((unused)) unsigned char tmp = '\0';

void
read_benchmark() {
    UnicodeChar *string;
    read_into_unicode_array(mix, &string);
}

void
iterate_benchmark(UnicodeChar **string) {
    while ((*string)->octet[0] != '\0') {
        tmp = (*string)->octet[0];
        ++(*string);
    }
}

main.c (output omitted):

int
main(int argc, char **argv) {
    for (int i = 0; i < target_runs; i++) {
        total_read_time = 0.0;
        printf("benchmarking %lu iterations\n", runs[i]);
        for (int j = 0; j < runs[i]; j++) {
            start_time = clock();
            read_benchmark();
            exec_time = (double) (clock() - start_time) / CLOCKS_PER_SEC;
            total_read_time += exec_time;
        }
        reads_total_time[i] = total_read_time;
    }

    UnicodeChar *string;
    read_into_unicode_array(mix, &string);

    for (int i = 0; i < target_runs; i++) {
        total_iterate_time = 0.0;
        printf("benchmarking %lu iterations\n", runs[i]);
        for (int j = 0; j < runs[i]; j++) {
            start_time = clock();
            iterate_benchmark(&string);
            exec_time = (double) (clock() - start_time) / CLOCKS_PER_SEC;
            total_iterate_time += exec_time;
        }
        iterates_total_time[i] = total_iterate_time;
    }
}

Result

Compiler info

> gcc -v

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.6.0
Thread model: posix

Different optimisation flags were used

-O0

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 56.000 56000.000 56.000 56000.000
100 0.001 659.000 659000.000 6.590 6590.000
1000 0.005 4902.000 4902000.000 4.902 4902.000
100000 0.335 335334.000 335334000.000 3.353 3353.340
1000000 3.442 3441791.000 3441790999.977 3.442 3441.791
10000000 35.227 35226991.999 35226991998.682 3.523 3522.699
100000000 370.454 370454129.527 370454129527.179 3.705 3704.541

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 2.000 2000.000 2.000 2000.000
100 0.000 69.000 69000.000 0.690 690.000
1000 0.001 708.000 708000.000 0.708 708.000
100000 0.069 69378.000 69378000.000 0.694 693.780
1000000 0.714 714062.000 714061999.998 0.714 714.062
10000000 7.088 7087756.001 7087756000.501 0.709 708.776
100000000 71.004 71003663.946 71003663945.989 0.710 710.037

-O1

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 33.000 33000.000 33.000 33000.000
100 0.000 293.000 293000.000 2.930 2930.000
1000 0.003 2939.000 2939000.000 2.939 2939.000
100000 0.266 266018.000 266018000.000 2.660 2660.180
1000000 2.700 2700406.000 2700405999.978 2.700 2700.406
10000000 26.816 26816024.998 26816024997.773 2.682 2681.602
100000000 296.365 296364930.637 296364930636.502 2.964 2963.649

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 0.000 0.000 0.000 0.000
100 0.000 70.000 70000.000 0.700 700.000
1000 0.001 677.000 677000.000 0.677 677.000
100000 0.069 68855.000 68855000.000 0.689 688.550
1000000 0.715 715358.000 715357999.998 0.715 715.358
10000000 7.508 7507516.001 7507516000.547 0.751 750.752
100000000 70.473 70472661.947 70472661946.961 0.705 704.727

-O2

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 56.000 56000.000 56.000 56000.000
100 0.000 461.000 461000.000 4.610 4610.000
1000 0.004 3695.000 3695000.000 3.695 3695.000
100000 0.241 241482.000 241482000.000 2.415 2414.820
1000000 2.450 2450306.000 2450305999.984 2.450 2450.306
10000000 24.482 24481698.998 24481698998.343 2.448 2448.170
100000000 269.061 269060824.683 269060824683.224 2.691 2690.608

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 1.000 1000.000 1.000 1000.000
100 0.000 67.000 67000.000 0.670 670.000
1000 0.001 669.000 669000.000 0.669 669.000
100000 0.072 71528.000 71528000.000 0.715 715.280
1000000 0.734 733623.000 733622999.998 0.734 733.623
10000000 7.384 7384042.001 7384042000.531 0.738 738.404
100000000 69.451 69451457.949 69451457949.064 0.695 694.515

-O3

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 43.000 43000.000 43.000 43000.000
100 0.000 283.000 283000.000 2.830 2830.000
1000 0.003 2965.000 2965000.000 2.965 2965.000
100000 0.249 248757.000 248757000.000 2.488 2487.570
1000000 2.479 2479015.000 2479014999.983 2.479 2479.015
10000000 24.326 24326037.998 24326037998.367 2.433 2432.604
100000000 269.239 269238602.683 269238602683.057 2.692 2692.386

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 2.000 2000.000 2.000 2000.000
100 0.000 75.000 75000.000 0.750 750.000
1000 0.001 768.000 768000.000 0.768 768.000
100000 0.072 71669.000 71669000.000 0.717 716.690
1000000 0.788 787709.000 787708999.998 0.788 787.709
10000000 7.707 7706768.001 7706768000.566 0.771 770.677
100000000 69.843 69843219.948 69843219948.280 0.698 698.432

-Ofast

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 45.000 45000.000 45.000 45000.000
100 0.000 362.000 362000.000 3.620 3620.000
1000 0.004 3609.000 3609000.000 3.609 3609.000
100000 0.249 249053.000 249053000.000 2.491 2490.530
1000000 2.627 2627024.000 2627023999.981 2.627 2627.024
10000000 34.668 34668188.998 34668188998.347 3.467 3466.819
100000000 278.181 278181358.668 278181358668.471 2.782 2781.814

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 8.000 8000.000 8.000 8000.000
100 0.000 147.000 147000.000 1.470 1470.000
1000 0.001 1307.000 1307000.000 1.307 1307.000
100000 0.072 71500.000 71500000.000 0.715 715.000
1000000 0.708 708458.000 708457999.998 0.708 708.458
10000000 7.068 7068220.000 7068220000.497 0.707 706.822
100000000 69.965 69965136.948 69965136948.167 0.700 699.651

-Os

Read string to UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 47.000 47000.000 47.000 47000.000
100 0.000 253.000 253000.000 2.530 2530.000
1000 0.003 2691.000 2691000.000 2.691 2691.000
100000 0.255 254665.000 254665000.000 2.547 2546.650
1000000 2.478 2477840.000 2477839999.983 2.478 2477.840
10000000 24.249 24248669.998 24248669998.382 2.425 2424.867
100000000 268.738 268738302.684 268738302683.953 2.687 2687.383

Iterate over UnicodeChar sequence benchmark

runs total time, s total time, μs total time, ns avg time per execution, μs avg time per execution, ns
1 0.000 1.000 1000.000 1.000 1000.000
100 0.000 72.000 72000.000 0.720 720.000
1000 0.001 704.000 704000.000 0.704 704.000
100000 0.070 70453.000 70453000.000 0.705 704.530
1000000 0.690 690229.000 690228999.998 0.690 690.229
10000000 6.906 6905566.000 6905566000.481 0.691 690.557
100000000 69.070 69070035.950 69070035949.866 0.691 690.700