Example #1
0
int main()
{
    MHASH *table;
    MERR *err;
    char str[101], *pstr[NODE_NUM];

    mtc_init("load.log", MTC_DEBUG);

    for (int i = 0; i < NODE_NUM; i++) {
        //mstr_rand_string(str, 100);
        //mstr_rand_string_fixlen(str, 100);
        snprintf(str, sizeof(str), "%d", i);

        pstr[i] = strdup(str);
    }

    err = mhash_init(&table, mhash_str_hash, mhash_str_comp, mhash_str_free);
    TRACE_NOK(err);

    mtimer_start();
    for (int i = 0; i < NODE_NUM; i++) {
        mhash_insert(table, pstr[i], NULL);
    }
    mtimer_stop("hash insert");

    mtimer_start();
    for (int i = 0; i < NODE_NUM; i++) {
        mhash_lookup(table, pstr[i]);
    }
    mtimer_stop("hash lookup");

    mhash_destroy(&table);

    return 0;
}
Example #2
0
File: cshdf.c Project: bigml/mbase
int main(int argc, char **argv, char **envp)
{
    char key[10];
    HDF *bignode;

    mtc_init("cshdf", 7);

    hdf_init(&bignode);

    for (int i = 0; i < 5003929; i++) {
        mstr_rand_string_with_len(key, 10);

        hdf_set_valuef(bignode, "%s.today=10", key);
        hdf_set_valuef(bignode, "%s.toweek=11", key);
        hdf_set_valuef(bignode, "%s.tomonth=12", key);
        hdf_set_valuef(bignode, "%s.total=234", key);

        if (i % 10000 == 0) printf("%d\n", i);
    }

    //hdf_dump(bignode, NULL);

    printf("child num %d\n", mcs_get_child_num(bignode, NULL));

    int count = 0;

    mtimer_start();

    HDF *cnode = hdf_obj_child(bignode);
    while (cnode) {
        char *name = hdf_obj_name(cnode);

        if (mcs_get_int_valuef(bignode, 0, "%s.today", name) != 10) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.toweek", name) != 11) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.tomonth", name) != 12) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.total", name) != 234) printf("error\n");

        count++;

        cnode = hdf_obj_next(cnode);
    }

    mtimer_stop("get time");

    printf("get child count %d\n", count);

    hdf_destroy(&bignode);

    return 0;
}
Example #3
0
File: pack.c Project: adderly/cmoon
int main(int argc, char **argv, char **envp)
{
    unsigned char buf[2048];
    int blen = 2048, len;
    char *s;
    HDF *hdf;
    
    //mconfig_parse_file("/tpl/oms.hdf", &g_cfg);

    mtimer_start();
    for (int i = 0; i < 100000; i++) {
        memset(buf, 2048, 0x0);
        len = pack_hdf(g_cfg, buf, blen);
        unpack_hdf(buf, len, &hdf);
        s = hdf_get_value(hdf, "manual.Layout", NULL);
        hdf_destroy(&hdf);
    }
    mtimer_stop(NULL);

    return 0;
}
Example #4
0
int main(int argc, char **argv, char **envp)
{
    struct json_object *jso;
    HDF *node;
    bson *doc;
    NEOERR *err;
    
    mtc_init("hdftest");

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        hdf_init(&node);
        //err = mjson_string_to_hdf(node, bdatam);
        OUTPUT_NOK(err);
        if (VERBERSE) hdf_dump(node, NULL);
        hdf_destroy(&node);
    }
    mtimer_stop("json => hdf");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        doc = mbson_new_from_string(bdatam, true);
        if (!doc) printf("bson error");
        if (VERBERSE) printf("%s\n", mbson_string(doc));
        bson_free(doc);
    }
    mtimer_stop("json => bson");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));


    

    hdf_init(&node);
    hdf_set_value(node, NULL, bdatam);
    //err = mjson_string_to_hdf(node, bdatam);
    OUTPUT_NOK(err);
    
    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        err = mjson_import_from_hdf(node, &jso);
        OUTPUT_NOK(err);
        if (VERBERSE) printf("%s\n", json_object_to_json_string(jso));
        json_object_put(jso);
    }
    mtimer_stop("hdf => json");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        err = mbson_import_from_hdf(node, &doc, true);
        OUTPUT_NOK(err);
        if (VERBERSE) printf("%s\n", mbson_string(doc));
        bson_free(doc);
    }
    mtimer_stop("hdf => bson");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));





    doc = mbson_new_from_string(bdatam, true);
    if (!doc) printf("bson error");

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        char *s = mbson_string(doc);
        if (!s) printf("bson->string error");
        if (VERBERSE) printf("%s\n", s);
        free(s);
    }
    mtimer_stop("bson => json");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        hdf_init(&node);
        //err = mbson_export_to_hdf(node, doc, false, false);
        OUTPUT_NOK(err);
        if (VERBERSE) hdf_dump(node, NULL);
        hdf_destroy(&node);
    }
    mtimer_stop("bson => hdf");
    //mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));
    bson_free(doc);

    return 0;
}