foreseen

A text-based gemini browser with prefetching
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

render-bench.cpp (3765B)


      1 #include <catch2/catch_test_macros.hpp>
      2 #include <catch2/benchmark/catch_benchmark_all.hpp>
      3 #include <rapidcheck.h>
      4 #include "../include/render.hpp"
      5 #include <ncurses.h>
      6 #include <rapidcheck/Check.h>
      7 #include <rapidcheck/Log.h>
      8 #include <string>
      9 
     10 std::string genAlNumNlSp(const int len) {
     11     static const char alphanum[] =
     12         "0123456789"
     13         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     14         "abcdefghijklmnopqrstuvwxyz\n ";
     15     std::string tmp_s;
     16     tmp_s.reserve(len);
     17 
     18     for (int i = 0; i < len; ++i) {
     19         tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
     20     }
     21     
     22     return tmp_s;
     23 }
     24 
     25 TEST_CASE("Benchmarking huge file scrolling") {
     26     setenv("EDITOR", "test" , 1);
     27     writeStringToFile(genAlNumNlSp(10000000), "tests/example.out");
     28     BENCHMARK("5 passes per iteration, 10m character file, load, scroll down 1000x, scroll up 1000x with 100x100 emulated terminal size") {
     29             for(int i = 0; i < 5; ++i) {
     30                 Browser* bPtr = new Browser {};
     31                 Browser& b = *bPtr;
     32                 DrawState ds {};
     33                 ds.bPtr = bPtr;
     34                 std::string cwd = std::filesystem::current_path();
     35                 std::string st = "file://" + cwd + "/tests/example.out";
     36 
     37                 REQUIRE(mainLoop(ds, b, 'o',100,100));
     38                 for(auto& ch: st) {
     39                     REQUIRE(mainLoop(ds, b, ch,100,100));
     40                 }
     41                 REQUIRE(mainLoop(ds, b, '\n',100,100));
     42                 REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == st);
     43 
     44                 for(int i = 0; i < 1000; ++i) {
     45                     REQUIRE(mainLoop(ds, b, KEY_DOWN,100,100));
     46                 }
     47                 for(int i = 0; i < 1000; ++i) {
     48                     REQUIRE(mainLoop(ds, b, KEY_UP,100,100));
     49                 }
     50             delete bPtr;
     51         }
     52     };
     53 }
     54 
     55 
     56 TEST_CASE("Benchmarking large file scrolling", "[.]") {
     57     setenv("EDITOR", "test" , 1);
     58     writeStringToFile(genAlNumNlSp(100000), "tests/example.out");
     59     BENCHMARK("100k character file, load, scroll down 100x, scroll up 100x with 100x100 emulated terminal size") {
     60         Browser* bPtr = new Browser {};
     61         Browser& b = *bPtr;
     62         DrawState ds {};
     63         ds.bPtr = bPtr;
     64         std::string cwd = std::filesystem::current_path();
     65         std::string st = "file://" + cwd + "/tests/example.out";
     66 
     67         REQUIRE(mainLoop(ds, b, 'o',100,100));
     68         for(auto& ch: st) {
     69             REQUIRE(mainLoop(ds, b, ch,100,100));
     70         }
     71         REQUIRE(mainLoop(ds, b, '\n',100,100));
     72         REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == st);
     73 
     74         for(int i = 0; i < 100; ++i) {
     75             REQUIRE(mainLoop(ds, b, KEY_DOWN,100,100));
     76         }
     77         for(int i = 0; i < 100; ++i) {
     78             REQUIRE(mainLoop(ds, b, KEY_UP,100,100));
     79         }
     80 
     81         delete bPtr;
     82     };
     83 }
     84 
     85 
     86 TEST_CASE("Benchmarking small file", "[.]") {
     87 
     88     setenv("EDITOR", "test" , 1);
     89 
     90     for(int x = 8; x < 10; ++x) {
     91         for(int y = 8; y < 10; ++y) {
     92             BENCHMARK("All line types - X: " + std::to_string(x) + " Y: " + std::to_string(y)) {
     93                 Browser* bPtr = new Browser {};
     94                 Browser& b = *bPtr;
     95                 DrawState ds {};
     96                 ds.bPtr = bPtr;
     97                 std::string cwd = std::filesystem::current_path();
     98                 std::string st = "file://" + cwd + "/tests/sites/all_line_types.gmi";
     99 
    100 
    101                 REQUIRE(mainLoop(ds, b, 'o',x,y));
    102 
    103                 for(auto& ch: st) {
    104                     REQUIRE(mainLoop(ds, b, ch,x,y));
    105                 }
    106 
    107                 REQUIRE(mainLoop(ds, b, '\n',x,y));
    108 
    109                 REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == st);
    110                 delete bPtr;
    111             };
    112         }
    113     }
    114 }
    115