<commit_before>/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkTypes.h"
#include "BenchTimer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"

namespace sk_tools {

BenchTimer* PictureBenchmark::setupTimer() {
#if SK_SUPPORT_GPU
    PictureRenderer* renderer = getRenderer();

    if (renderer != NULL && renderer->isUsingGpuDevice()) {
        return new BenchTimer(renderer->getGLContext());
    } else {
        return new BenchTimer(NULL);
    }
#else
    return new BenchTimer(NULL);
#endif
}

void PipePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();

    BenchTimer* timer = this->setupTimer();

    timer->start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.render();
    }
    timer->end();

    fRenderer.end();

    SkDebugf("pipe: msecs = %6.2f", timer->fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats);
    }
    SkDebugf("\n");

    delete timer;
}

void RecordPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer* timer = setupTimer();
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        timer->start();
        recorder->drawPicture(*pict);
        timer->end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer->fWall;
        }
    }

    SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
}

void SimplePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();

    BenchTimer* timer = this->setupTimer();

    timer->start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.render();
    }
    timer->end();

    fRenderer.end();

    SkDebugf("simple: msecs = %6.2f", timer->fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats);
    }
    SkDebugf("\n");

    delete timer;
}

void TiledPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.drawTiles();

    BenchTimer* timer = setupTimer();
    timer->start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.drawTiles();
    }
    timer->end();

    fRenderer.end();

    SkDebugf("%i_tiles_%ix%i: msecs = %6.2f", fRenderer.numTiles(), fRenderer.getTileWidth(),
            fRenderer.getTileHeight(), timer->fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer->fGpu / fRepeats);
    }
    SkDebugf("\n");
}

void UnflattenPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer* timer = setupTimer();
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        recorder->drawPicture(*pict);

        timer->start();
        replayer.endRecording();
        timer->end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer->fWall;
        }
    }

    SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
}

}
<commit_msg>resetState is called between every benchmark run.<commit_after>/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkTypes.h"
#include "BenchTimer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"

namespace sk_tools {

BenchTimer* PictureBenchmark::setupTimer() {
#if SK_SUPPORT_GPU
    PictureRenderer* renderer = getRenderer();

    if (renderer != NULL && renderer->isUsingGpuDevice()) {
        return new BenchTimer(renderer->getGLContext());
    } else {
        return new BenchTimer(NULL);
    }
#else
    return new BenchTimer(NULL);
#endif
}

void PipePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();
    fRenderer.resetState();

    BenchTimer* timer = this->setupTimer();
    double wall_time = 0;
#if SK_SUPPORT_GPU
    double gpu_time = 0;
#endif

    for (int i = 0; i < fRepeats; ++i) {
        timer->start();
        fRenderer.render();
        timer->end();
        fRenderer.resetState();

        wall_time += timer->fWall;
#if SK_SUPPORT_GPU
        if (fRenderer.isUsingGpuDevice()) {
            gpu_time += timer->fGpu;
        }
#endif
    }

    fRenderer.end();

    SkDebugf("pipe: msecs = %6.2f", wall_time / fRepeats);
#if SK_SUPPORT_GPU
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
    }
#endif
    SkDebugf("\n");

    delete timer;
}

void RecordPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer* timer = setupTimer();
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        timer->start();
        recorder->drawPicture(*pict);
        timer->end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer->fWall;
        }
    }

    SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
}

void SimplePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();
    fRenderer.resetState();


    BenchTimer* timer = this->setupTimer();
    double wall_time = 0;
#if SK_SUPPORT_GPU
    double gpu_time = 0;
#endif

    for (int i = 0; i < fRepeats; ++i) {
        timer->start();
        fRenderer.render();
        timer->end();
        fRenderer.resetState();

        wall_time += timer->fWall;
#if SK_SUPPORT_GPU
        if (fRenderer.isUsingGpuDevice()) {
            gpu_time += timer->fGpu;
        }
#endif
    }

    fRenderer.end();

    SkDebugf("simple: msecs = %6.2f", wall_time / fRepeats);
#if SK_SUPPORT_GPU
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
    }
#endif
    SkDebugf("\n");

    delete timer;
}

void TiledPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.drawTiles();
    fRenderer.resetState();

    BenchTimer* timer = setupTimer();
    double wall_time = 0;
#if SK_SUPPORT_GPU
    double gpu_time = 0;
#endif

    for (int i = 0; i < fRepeats; ++i) {
        timer->start();
        fRenderer.drawTiles();
        timer->end();
        fRenderer.resetState();

        wall_time += timer->fWall;
#if SK_SUPPORT_GPU
        if (fRenderer.isUsingGpuDevice()) {
            gpu_time += timer->fGpu;
        }
#endif
    }

    fRenderer.end();

    SkDebugf("%i_tiles_%ix%i: msecs = %6.2f", fRenderer.numTiles(), fRenderer.getTileWidth(),
            fRenderer.getTileHeight(), wall_time / fRepeats);
#if SK_SUPPORT_GPU
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
    }
#endif
    SkDebugf("\n");
}

void UnflattenPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer* timer = setupTimer();
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        recorder->drawPicture(*pict);

        timer->start();
        replayer.endRecording();
        timer->end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer->fWall;
        }
    }

    SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
}

}

{'fraction_non_alphanumeric': 0.14279398762157383, 'fraction_numerical': 0.007515473032714412, 'mean_word_length': 2.484405082787832, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6171085', 'n_tokens_mistral': 3213, 'n_tokens_neox': 3067, 'n_words': 721}