<commit_before>package no.javazone;

import org.junit.Assert;
import org.junit.Test;

import java.util.function.Supplier;
import java.util.stream.IntStream;

public class ThreadTest {

    @Test
    public void should_run_8_times_as_fast_with_8_cores() throws Exception {
        long t = System.currentTimeMillis();
        int processors = Runtime.getRuntime().availableProcessors();
        IntStream.range(0, processors * 100).forEach(i->Big.task());
        long duration = System.currentTimeMillis() - t;
        long mem = Runtime.getRuntime().totalMemory();
        TaskRunner runner = new TaskRunner(processors * 100);
        Supplier task = Big::task;
        TaskRunner.Result result = runner.runTask(() -> new Thread(runner.track(task)).start());

        Assert.assertTrue(String.format("Used %d compared to %d", result.memory, mem), result.memory > mem * processors/2);
        Assert.assertTrue(String.format("Expecting 8 times speedup, got only %d. Single Threaded time was %d", duration / result.duration, duration), result.duration <= (duration / (processors-1)));
    }
}<commit_msg>only assert on processing time and present better output message<commit_after>package no.javazone;

import org.junit.Assert;
import org.junit.Test;

import java.util.stream.IntStream;

public class ThreadTest {

    @Test
    public void should_run_8_times_as_fast_with_8_cores() throws Exception {
        int processors = Runtime.getRuntime().availableProcessors();
        int runs = processors * 100;
        TaskRunner.Result singleThreadedResult = singleThreaded(runs);
        TaskRunner.Result multiThreadedResult = multiThreaded(runs);
        String msg = String.format("Expecting 8 times speedup, got only %d. Single Threaded time was %d",
                singleThreadedResult.duration / multiThreadedResult.duration,
                singleThreadedResult.duration);

        Assert.assertTrue(
                msg,
                multiThreadedResult.duration <= (singleThreadedResult.duration / (processors-1)));
    }

    private TaskRunner.Result multiThreaded(int runs) throws InterruptedException {
        TaskRunner runner = new TaskRunner(runs);
        return runner.runTask(() -> new Thread(runner.track(Big::task)).start());
    }

    private TaskRunner.Result singleThreaded(int runs) {
        long t = System.currentTimeMillis();
        IntStream.range(0, runs).forEach(i-> Big.task());
        return new TaskRunner.Result(System.currentTimeMillis() - t, Runtime.getRuntime().totalMemory());
    }
}
{'fraction_non_alphanumeric': 0.11062821019359936, 'fraction_numerical': 0.007902015013828527, 'mean_word_length': 3.4499121265377855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5551693', 'n_tokens_mistral': 704, 'n_tokens_neox': 681, 'n_words': 166}