lcompilers / lc

C++ compiler
MIT License
26 stars 7 forks source link

Ported ``integration_tests/test_list_01.py`` from LPython and add support for ``std::vector`` in LC to compile it #104

Closed czgdp1807 closed 8 months ago

certik commented 8 months ago

Excellent! How is the performance on this one?

czgdp1807 commented 8 months ago

Haven't checked yet. But ASR is the same so performance should be the same. Will check during the weekend.

certik commented 8 months ago

Performance will be the same as LPython, but I can't remember if we can beat Clang on this benchmark or not.

czgdp1807 commented 8 months ago
#include <vector>
#include <iostream>

int main() {
    std::vector<int32_t> v;
    for( int32_t i = 0; i < 400000000; i++ ) {
        v.push_back(i);
    }
    std::cout<<v[100000];
}
(lc) 21:35:58:~/lc_project/lc % clang++ ../debug.cpp -std=c++17
(lc) 21:36:04:~/lc_project/lc % time ./a.out                   
100000./a.out  12.70s user 0.49s system 99% cpu 13.286 total
(lc) 21:36:18:~/lc_project/lc % lc ../debug.cpp -o a.out       
(lc) 21:37:17:~/lc_project/lc % time ./a.out                   
100000
./a.out  0.30s user 0.11s system 91% cpu 0.457 total
(lc) 21:37:20:~/lc_project/lc % clang++ ../debug.cpp -std=c++17 -O3
(lc) 21:37:30:~/lc_project/lc % time ./a.out                       
100000./a.out  0.25s user 0.26s system 91% cpu 0.560 total

lc NOFAST is 29.07x faster than clang++ NOFAST (16.0.6) and 1.22x faster than clang++ -O3. I can't enable lc --fast via command line. I will add this option on Monday next week so that we can benchmark against clang++ without issues.

Update

After adding support for --fast tag (https://github.com/lcompilers/lc/pull/110),

(lc) 0:18:07:~/lc_project/lc % lc /Users/czgdp1807/lc_project/debug.cpp --fast -o a.out   
(lc) 0:18:16:~/lc_project/lc % time ./a.out
100000./a.out  0.15s user 0.12s system 91% cpu 0.298 total
(lc) 0:18:21:~/lc_project/lc % clang++ ../debug.cpp -O3 -ffast-math
(lc) 0:19:31:~/lc_project/lc % time ./a.out
100000./a.out  0.26s user 0.29s system 91% cpu 0.601 total

So in release mode, LC is 2.02x faster than clang++ -O3 -ffast-math. This benchmark is just on std::vector::push_back. LC is the fastest of all.

certik commented 8 months ago

Great job. This is very promising. Let me review this carefully and double check everything.