예제 #1
0
void test_creation(GThreadFunc f, sc_int32 count, sc_int thread_count)
{
    int test_count = count / thread_count;

    g_message("Threads count: %d, Test per thread: %d", thread_count, test_count);

    tGThreadVector threads;
    threads.reserve(thread_count);


    print_storage_statistics();

    g_test_timer_start();
    for (size_t i = 0; i < thread_count; ++i)
    {
        GThread * thread = g_thread_try_new(0, f, GINT_TO_POINTER(test_count), 0);
        if (thread == 0)
            continue;
        threads.push_back(thread);
    }

    for (size_t i = 0; i < thread_count; ++i)
        g_assert(GPOINTER_TO_INT(g_thread_join(threads[i])) == test_count);

    printf("Time: %lf\n", g_test_timer_elapsed());

    print_storage_statistics();
}
예제 #2
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test6()
{
    sc_uint32 i, j;
    sc_addr addr;
    sc_stream *stream = 0;
    sc_addr *results = 0;
    sc_uint32 results_count = 0;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    //g_snprintf(test, 1024, "../CMakeLists.txt");
    g_timer_reset(timer);
    g_timer_start(timer);

    for (i = 0; i < link_append_count; i++)
    {
        //addr = sc_storage_link_new();
        printf("Find addrs for content %d\t", i);

        stream = sc_stream_memory_new((char*)&i, sizeof(i), SC_STREAM_READ, SC_FALSE);

        if (sc_storage_find_links_with_content(stream, &results, &results_count) == SC_RESULT_OK)
        {
            printf("founded: \n");
            for (j = 0; j < results_count; j++)
                printf("seg=%d, offset=%d\n", results[j].seg, results[j].offset);
            g_free(results);
            results = 0;
        }else
            printf("error\n");

        sc_stream_free(stream);
    }

    g_timer_stop(timer);

    printf("Created links: %d\n", link_append_count);
    printf("Links per second: %f\n", link_append_count / g_timer_elapsed(timer, 0));

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
예제 #3
0
void test_combined_creation()
{
    int thread_count = g_thread_count;
    int test_count = (g_task_count) / thread_count;

    g_message("Threads count: %d, Test per thread: %d", thread_count, test_count);

    tGThreadVector threads;
    threads.reserve(thread_count);

    s_default_ctx = sc_memory_initialize(&params);
    print_storage_statistics();    

    g_test_timer_start();
    for (size_t i = 0; i < thread_count; ++i)
    {
        GThreadFunc f = create_node_thread;
        switch(g_random_int() % 3)
        {
        case 0:
            f = create_link_thread;
            break;
        case 1:
            f = create_arc_thread;
            break;
        default:
            break;
        }

        GThread * thread = g_thread_try_new(0, f, GINT_TO_POINTER(test_count), 0);
        if (thread == 0)
            continue;
        threads.push_back(thread);
    }

    for (size_t i = 0; i < thread_count; ++i)
        g_assert(GPOINTER_TO_INT(g_thread_join(threads[i])) == test_count);

    printf("Time: %lf\n", g_test_timer_elapsed());

    print_storage_statistics();
    sc_memory_shutdown(SC_FALSE);
}
예제 #4
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test7()
{
    sc_uint32 i, j;
    sc_addr addr, addr1, addr2;
    sc_addr new_addr;
    sc_event *event1, *event2, *event3, *event4;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    g_timer_reset(timer);
    g_timer_start(timer);

    addr = sc_storage_node_new(0);
    addr1 = sc_storage_node_new(0);
    printf("Register events\n");
    event1 = sc_event_new(addr, SC_EVENT_ADD_OUTPUT_ARC, 0, &event_callback, 0);
    event2 = sc_event_new(addr1, SC_EVENT_ADD_INPUT_ARC, 1, &event_callback, 0);
    event3 = sc_event_new(addr, SC_EVENT_REMOVE_OUTPUT_ARC, 2, &event_callback, 0);
    event4 = sc_event_new(addr1, SC_EVENT_REMOVE_INPUT_ARC, 3, &event_callback, 0);

    addr2 = sc_storage_arc_new(0, addr, addr1);
    sc_storage_element_free(addr2);

    printf("Unregister events\n");
    sc_event_destroy(event1);
    sc_event_destroy(event2);
    sc_event_destroy(event3);
    sc_event_destroy(event4);

    addr2 = sc_storage_arc_new(0, addr, addr1);
    sc_storage_element_free(addr2);

    g_timer_stop(timer);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
예제 #5
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test3()
{
    sc_addr node[10], arc[10][10];
    sc_uint32 i, j;

    printf("Create 10 nodes and 100 arcs, that connect nodes each other\n");
    for (i = 0; i < 10; i++)
        node[i] = sc_storage_element_new(sc_type_node);

    for (i = 0; i < 10; i++)
        for (j = 0; j < 10; j++)
            arc[i][j] = sc_storage_arc_new(0, node[i], node[j]);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    printf("Delete 5 nodes\n");
    for (i = 0; i < 5; i++)
        sc_storage_element_free(node[i]);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();
}
예제 #6
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test5()
{
    sc_uint32 i;
    sc_addr addr;
    sc_stream *stream = 0;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    printf("Create %d links\n", link_append_count);

    //g_snprintf(test, 1024, "../CMakeLists.txt");
    g_timer_reset(timer);
    g_timer_start(timer);
    for (i = 0; i < link_append_count; i++)
    {
        addr = sc_storage_link_new();

        printf("Created sc-link: seg=%d, offset=%d, content=%d\n", addr.seg, addr.offset, i);

        stream = sc_stream_memory_new((char*)&i, sizeof(i), SC_STREAM_READ, SC_FALSE);
        sc_storage_set_link_content(addr, stream);
        sc_stream_free(stream);
    }

    g_timer_stop(timer);

    printf("Created links: %d\n", link_append_count);
    printf("Links per second: %f\n", link_append_count / g_timer_elapsed(timer, 0));

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
예제 #7
0
void test9()
{
    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    printf("Collect and delete garbage...\n");
    g_timer_reset(timer);
    g_timer_start(timer);

    sc_storage_update_segments();

    g_timer_stop(timer);



    printf("Elapsed time: %f\n", g_timer_elapsed(timer, 0));
    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);

}
예제 #8
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test1()
{
    sc_uint idx = 0;
    sc_addr id, id2;
    sc_uint32 count = 0;

    printf("Element size: %d bytes\n", sizeof(sc_element));
    printf("Segment size: %d elements\n", SEGMENT_SIZE);

    timer = g_timer_new();
    print_storage_statistics();
    printf("--- Node creation ---\n");
    g_timer_start(timer);
    for (idx = 0; idx < nodes_append_count; idx++)
    {
        id = sc_storage_element_new(sc_type_node);
        //g_printf("uri: %d\t%d\n", uri.seg, uri.id);
    }
    g_timer_stop(timer);
    printf("Time: %f s\n", g_timer_elapsed(timer, 0));
    printf("Nodes per second: %f\n", (float)nodes_append_count / g_timer_elapsed(timer, 0));
    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_reset(timer);
    printf("--- Node segmentation ---\n");
    count = 0;

    printf("Prepare test...\n");
    for (idx = 1; idx < nodes_remove_count + 1; idx++)
    {
        if (idx % 10 < 5)
        {
            id.seg = idx / SEGMENT_SIZE;
            id.offset = idx % SEGMENT_SIZE;
            /*do
      {
    id = get_random_addr(sc_type_node);
      }
      while(!sc_storage_is_element(id) && is_sc_addr_in_segment_node_vector(id));*/
            if (sc_storage_is_element(id))
                segment_node_del.push_back(id);
        }
    }

    printf("Run test...\n");
    g_timer_start(timer);

    sc_uint32 n = segment_node_del.size();
    for (sc_uint32 i = 0; i < n; ++i)
        sc_storage_element_free(segment_node_del[i]);

    n = nodes_remove_count - n;
    for (sc_uint32 i = 0; i < n; i++)
        sc_storage_node_new(0);

    g_timer_stop(timer);

    segment_node_del.clear();

    printf("Time: %f s\n", g_timer_elapsed(timer, 0));
    printf("Elements per second: %f\n", (float)nodes_remove_count / g_timer_elapsed(timer, 0));
    printf("Segments count: %d\n", sc_storage_get_segments_count());
    printf("Element free calls: %u\n", segment_node_del.size());
    print_storage_statistics();


    g_timer_reset(timer);
    printf("--- Arcs creation ---\n");
    count = 0;

    printf("Prepare...\n");
    for (idx = 0; idx < arcs_append_count; idx++)
    {
        do
        {
            id = get_random_addr(0);
        }while (!sc_storage_is_element(id));

        do
        {
            id2 = get_random_addr(0);
        }while (!sc_storage_is_element(id2));

        arc_creation_vector.push_back(id);
        arc_creation_vector.push_back(id2);
    }

    printf("Run...\n");
    g_timer_start(timer);
    n = arc_creation_vector.size() / 2;
    for (sc_uint32 i = 0; i < n; ++i)
    {
        sc_storage_arc_new(sc_type_arc_common, arc_creation_vector[i], arc_creation_vector[i + n]);
    }

    g_timer_stop(timer);
    printf("Timer: %fs\n", g_timer_elapsed(timer, 0));
    printf("Arcs per second: %f\n", (float)n / g_timer_elapsed(timer, 0));
    printf("Segments count: %d\n", sc_storage_get_segments_count());

    print_storage_statistics();

    g_timer_destroy(timer);
}
예제 #9
0
파일: test.cpp 프로젝트: drax08/sc-machine
void test4()
{
    sc_addr node[10], arc[10][10];
    sc_uint32 i, j;
    sc_iterator3 *it = 0;
    sc_addr addr1, addr2, addr3;

    printf("Create 10 nodes and 100 arcs, that connect nodes each other\n");
    for (i = 0; i < 10; i++)
        node[i] = sc_storage_element_new(sc_type_node);

    for (i = 0; i < 10; i++)
        for (j = 0; j < 10; j++)
            arc[i][j] = sc_storage_arc_new(0, node[i], node[j]);

    print_storage_statistics();
    printf("---\nTest iterator3_f_a_a\n");
    for (i = 0; i < 10; i++)
    {
        it = sc_iterator3_f_a_a_new(node[i], 0, 0);
        g_assert(it != 0);

        printf("Node %d:\n", i);
        while (sc_iterator3_next(it))
        {
            addr1 = sc_iterator3_value(it, 0);
            addr2 = sc_iterator3_value(it, 1);
            addr3 = sc_iterator3_value(it, 2);

            printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset);
        }

        sc_iterator3_free(it);
    }

    printf("---\nTest iterator3_a_a_f\n");
    for (i = 0; i < 10; i++)
    {
        it = sc_iterator3_a_a_f_new(0, 0, node[i]);
        g_assert(it != 0);

        printf("Node %d:\n", i);
        while (sc_iterator3_next(it))
        {
            addr1 = sc_iterator3_value(it, 0);
            addr2 = sc_iterator3_value(it, 1);
            addr3 = sc_iterator3_value(it, 2);

            printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset);
        }

        sc_iterator3_free(it);
    }

    printf("---\nTest iterator3_f_a_f\n");
    for (i = 0; i < 10; i++)
    {
        it = sc_iterator3_f_a_f_new(node[i], 0, node[9 - i]);
        g_assert(it != 0);

        printf("Node %d:\n", i);
        while (sc_iterator3_next(it))
        {
            addr1 = sc_iterator3_value(it, 0);
            addr2 = sc_iterator3_value(it, 1);
            addr3 = sc_iterator3_value(it, 2);

            printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset);
        }

        sc_iterator3_free(it);
    }

    // iterator allocations
    printf("---\nTest iterator allocation(dealocation) speed...\n");

    timer = g_timer_new();

    g_timer_reset(timer);
    g_timer_start(timer);

    for (i = 0; i < iterator_alloc_count; i++)
    {
        it = sc_iterator3_f_a_a_new(node[0], 0, 0);
        sc_iterator3_free(it);
    }

    g_timer_stop(timer);
    printf("Allocated iterators: %d\n", iterator_alloc_count);
    printf("Allocation/deallocation per second: %f\n", iterator_alloc_count / g_timer_elapsed(timer, 0));

    g_timer_destroy(timer);

}
예제 #10
0
void test8()
{
    sc_addr node[10], arc[10][10], addr_arc;
    sc_uint32 i, j;
    sc_iterator3 *it = 0;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    printf("Create 10 nodes and 100 arcs, that connect nodes each other\n");
    for (i = 0; i < 10; i++)
        node[i] = sc_memory_node_new(sc_type_node);

    for (i = 0; i < 10; i++)
        for (j = 0; j < 10; j++)
            arc[i][j] = sc_memory_arc_new(0, node[i], node[j]);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    printf("Delete 5 nodes\n");
    for (i = 0; i < 5; i++)
        sc_memory_element_free(node[i]);

    // iterate element for check
    it = sc_iterator3_f_a_a_new(node[9], 0, 0);
    while (sc_iterator3_next(it) == SC_TRUE)
    {
        addr_arc = sc_iterator3_value(it, 1);
        printf("Arc: %d, %d\n", addr_arc.seg, addr_arc.offset);
    }
    sc_iterator3_free(it);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_stop(timer);

    printf("Collect and delete garbage...\n");
    g_timer_reset(timer);
    g_timer_start(timer);

    sc_storage_update_segments();

    g_timer_stop(timer);

    // iterate element for check
    it = sc_iterator3_f_a_a_new(node[9], 0, 0);
    while (sc_iterator3_next(it) == SC_TRUE)
    {
        addr_arc = sc_iterator3_value(it, 1);
        printf("Arc: %d, %d\n", addr_arc.seg, addr_arc.offset);
    }
    sc_iterator3_free(it);

    printf("Elapsed time: %f\n", g_timer_elapsed(timer, 0));
    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);

}