Example #1
0
void benchmark_work_fork(const char *filepath, const char *filename, benchmark_work_callback_f callback, FILE *out_fh)
{
    struct benchmark_res_html res = benchmark_load_html_file(filepath);
    struct benchmark_ctx ctx = {0, 0, NULL, 0};
    
    size_t mem_start    = proc_stat_getCurrentRSS();
    uint64_t time_start = myhtml_hperf_clock();
    
    callback(filename, res.html, res.size, &ctx);
    
    uint64_t time_end = myhtml_hperf_clock();
    size_t mem_end    = proc_stat_getPeakRSS();
    
    free(res.html);
    
    long long mem_used = mem_end - mem_start;
    double work_time = myhtml_absolute_difference(time_start, time_end);
    
    fprintf(out_fh, "\"%s\";%zu;%0.5f;%lld\n", filename, res.size, work_time, mem_used);
}
Example #2
0
void benchmark_work(const char *filepath, const char *filename, benchmark_work_callback_f callback, struct benchmark_ctx *ctx, FILE *out_fh)
{
    struct benchmark_res_html res = benchmark_load_html_file(filepath);
    
    uint64_t time_start = myhtml_hperf_clock();
    
    callback(filename, res.html, res.size, ctx);
    
    uint64_t time_end = myhtml_hperf_clock();
    
    free(res.html);
    
    double work_time = myhtml_absolute_difference(time_start, time_end);
    
    ctx->count++;
    ctx->sum += work_time;
    ctx->total_file_size += res.size;
    
    fprintf(out_fh, "\"%s\";%zu;%0.5f;%lld\n", filename, res.size, work_time, 0LL);
}
Example #3
0
int main(int argc, const char * argv[])
{
//    chunk_test();
//    return 0;
//
    //myhtml_encoding_decode_single_byte(0xf4);
    
//    myhtml_encoding_result_t res_data = {0, 0, 0, 0, 0, 0};
//    
//    unsigned char data[20];
//    data[0] = 0xAC;
//    data[1] = 0xB1;
//    data[2] = 0x42;
//    data[3] = 0x4F;
//    data[4] = 0x51;
//    data[5] = 0x1B;
//    data[6] = 0x28;
//    data[7] = 0x42;
//    data[8] = 0;
//    
//    //myhtml_encoding_dec_to_char(54936, data);
//    
//    enum myhtml_encoding_status status = MyHTML_ENCODING_STATUS_CONTINUE;
//    
//    size_t i = 0;
//    while (status & MyHTML_ENCODING_STATUS_CONTINUE) {
//        status = myhtml_encoding_decode_euc_kr(data[i], &res_data);
//        i++;
//    }
//    
//    myhtml_string_convert_dec_to_ansi_utf8(res_data.result, (char *)data);
//    
//    return 0;
//    chunk_test();
//    uint64_t all_start1 = myhtml_hperf_clock(NULL);
//    test_all();
//    uint64_t all_stop1 = myhtml_hperf_clock(NULL);
//
//    myhtml_hperf_print("Parse html", all_start1, all_stop1, stdout);
//    return 0;
    
    /* Default path or argument value */
    //const char* path = "/new/C-git/myhtml/test/test.html";
    //const char* path = "/new/C-git/broken.html";
    const char* path = "/new/C-git/test_full.html";
    
    if (argc == 2) {
        path = argv[1];
    }
    
    setbuf(stdout, 0);
    
    myhtml_t* myhtml = myhtml_create();
    myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 1, 0);
    
    struct res_html res  = load_html(path);
    
    uint64_t all_start = myhtml_hperf_clock(NULL);
    uint64_t tree_init_start = myhtml_hperf_clock(NULL);
    
    // init once for N html
    myhtml_tree_t* tree = myhtml_tree_create();
    myhtml_tree_init(tree, myhtml);
    
    uint64_t tree_init_stop = myhtml_hperf_clock(NULL);
    uint64_t parse_start = myhtml_hperf_clock(NULL);
    
    myhtml_encoding_t encoding;
    myhtml_encoding_detect(res.html, res.size, &encoding);
    
    for(size_t i = 0; i < 1; i++)
    {
        //myhtml_parse(tree, text, strlen(text));
        myhtml_parse_single(tree, encoding, res.html, res.size);
//        myhtml_parse(tree, MyHTML_ENCODING_UTF_8, res.html, res.size);
        
//        myhtml_tree_print_node_childs(tree, tree->document, stdout, 0);
    }
    //usleep(100000000);
    
    uint64_t parse_stop = myhtml_hperf_clock(NULL);
    uint64_t all_stop = myhtml_hperf_clock(NULL);
    
    printf("\n\nInformation:\n");
    printf("Timer (%llu ticks/sec):\n", (unsigned long long) myhtml_hperf_res(NULL));
    myhtml_hperf_print("\tFirst Tree init", tree_init_start, tree_init_stop, stdout);
    myhtml_hperf_print("\tParse html", parse_start, parse_stop, stdout);
    myhtml_hperf_print("\tTotal", all_start, all_stop, stdout);
    printf("\n");
    
    myhtml_tree_destroy(tree);
    myhtml_destroy(myhtml);
    free(res.html);
    
    return 0;
}