void ArrayVersion_misaligned(BenchmarkExt<int>& bench)
{
    bench.beginImplementation("Array<T,1> (misal.)");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();
        long iters = bench.getIterations();

        cout << bench.currentImplementation() << ": N = " << N << endl;


    Array<double,1> xfill(N+2);
    Array<double,1> x(xfill(Range(0,N+0-1)));
    initializeRandomDouble(x.dataFirst(), N);

    Array<double,1> efill(N+2);
    Array<double,1> e(efill(Range(1,N+1-1)));
    initializeRandomDouble(e.dataFirst(), N);


        bench.start();
        for (long i=0; i < iters; ++i)
        {
            x = exp(e);
            sink();
        }
        bench.stop();

        bench.startOverhead();
        for (long i=0; i < iters; ++i) {
            sink();
	}

        bench.stopOverhead();
    }

    bench.endImplementation();
}
Exemple #2
0
void UILayout::update(float dt) {

    updateZIndex();

    vec2 inner = vec2(0.0f, 0.0f);

    int visible_elements = 0;

    std::list<UIElement*> fill_vert_elements;
    std::list<UIElement*> fill_horiz_elements;

    for(UIElement* e: elements) {
        e->resetRect();
        e->update(dt);

        if(e->isVisible()) {
            visible_elements++;

            if(e->fillHorizontal()) fill_horiz_elements.push_back(e);
            if(e->fillVertical())   fill_vert_elements.push_back(e);

            vec2 r = e->getRect();

            if(horizontal) {
                inner.x += r.x;
                inner.y = std::max(inner.y, r.y);
            } else {
                inner.x = std::max(inner.x, r.x);
                inner.y += r.y;
            }
        }
    }

    vec4 margin = getMargin();

    if(horizontal) {
        inner.x += margin.x+margin.z + ((float)visible_elements-1) * padding.x;
        inner.y += margin.y+margin.w;
    } else {
        inner.x += margin.x+margin.z;
        inner.y += margin.y+margin.w + ((float)visible_elements-1) * padding.y;
    }

    rect = glm::max(min_rect, inner);

    if(fill_vert_elements.empty() && fill_horiz_elements.empty()) return;

    vec2 filler = glm::max(vec2(0.0f), vec2(rect-inner)) + expanded_rect;

    if(horizontal && !fill_horiz_elements.empty()) {
        filler.x /= (float) fill_horiz_elements.size();
    } else if(!fill_vert_elements.empty()) {
        filler.y /= (float) fill_vert_elements.size();
    }

    std::list<UIElement*> fill_elements;
    fill_elements.insert(fill_elements.end(), fill_horiz_elements.begin(), fill_horiz_elements.end());
    fill_elements.insert(fill_elements.end(), fill_vert_elements.begin(), fill_vert_elements.end());

    fill_elements.unique();

    for(UIElement* e: fill_elements) {

        vec2 efill(0.0f);

        if(e->fillHorizontal()) {
            if(!horizontal) efill.x = filler.x + glm::max(0.0f, inner.x - e->rect.x - margin.x - margin.z);
            else efill.x = filler.x;
        }

        if(e->fillVertical()) {
            if(horizontal) efill.y = filler.y + glm::max(0.0f, inner.y - e->rect.y - margin.y - margin.w);
            else efill.y = filler.y;
        }

        if(efill.x > 0.0f || efill.y > 0.0f) {
            e->expandRect(efill);
            e->update(0.0f);
        }
    }

    if(!elements.empty() && elements.front()->getType() == UI_SELECT) debugLog("first element is a select");
}