<commit_before><?php
/**
 * Test application class
 *
 * @file    TestApplication.php
 *
 * PHP version 5.3.9+
 *
 * @author  <NAME> <<EMAIL>>
 * @date    Сбт Фев 16 17:01:16 2013
 * @copyright The BSD 3-Clause License.
 */
namespace Tests;

use Veles\Application\Application;
use Veles\Tools\CliColor;

/**
 * Class TestApplication
 * @package Classes
 */
class TestApplication extends Application
{
	/**
	 * @var array Results array
	 */
	private static $results = array();
	protected static $repeats = 10000;

	/**
	 * @param int $repeats
	 */
	final public static function setRepeats($repeats)
	{
		static::$repeats = $repeats;
	}

	/**
	 * @return int
	 */
	final public static function getRepeats()
	{
		return static::$repeats;
	}

	/**
	 * @param array $results
	 */
	final public static function setResults($results)
	{
		self::$results = $results;
	}

	/**
	 * @return array
	 */
	final public static function getResults()
	{
		return self::$results;
	}

	/**
	 * Display results
	 */
	final public static function showResults()
	{
		$results = self::getResults();
		asort($results);
		$best = key($results);
		$string = new CliColor;

		printf(
			"%-10s\t%-15s\t%-10s\t%-15s\n",
			'Test name', 'Repeats', 'Result', 'Performance'
		);

		foreach ($results as $name => $value) {
			$color = ($name === $best || $results[$best] === $value)
				? 'green' : 'red';

			$percent = self::getPercentDiff($results[$best], $value);

			$string->setColor($color);
			$string->setString($value);
			printf(
				"%-10s\t%-15s\t%-10s sec\t%-15s\n",
				$name, self::getRepeats(), $string, $percent . '%'
			);
		}
	}

	private static function getPercentDiff($best, $current)
	{
		$diff = $current - $best;
		$percent = $best / 100;
		$value = round($diff / $percent, 3);

		$result = new CliColor;

		if ($value > 0) {
			$result->setColor('red');
			$result->setstring("-$value");
		} else {
			$result->setColor('green');
			$result->setstring("+$value");
		}

		return $result;
	}

	/**
	 * Add result for further displaying
	 *
	 * @param string $name
	 * @param float $value
	 */
	final public static function addResult($name, $value)
	{
		self::$results[$name] = $value;
	}
}
<commit_msg>Change justification params in result output<commit_after><?php
/**
 * Test application class
 *
 * @file    TestApplication.php
 *
 * PHP version 5.3.9+
 *
 * @author  <NAME> <<EMAIL>>
 * @date    Сбт Фев 16 17:01:16 2013
 * @copyright The BSD 3-Clause License.
 */
namespace Tests;

use Veles\Application\Application;
use Veles\Tools\CliColor;

/**
 * Class TestApplication
 * @package Classes
 */
class TestApplication extends Application
{
	/**
	 * @var array Results array
	 */
	private static $results = array();
	protected static $repeats = 10000;

	/**
	 * @param int $repeats
	 */
	final public static function setRepeats($repeats)
	{
		static::$repeats = $repeats;
	}

	/**
	 * @return int
	 */
	final public static function getRepeats()
	{
		return static::$repeats;
	}

	/**
	 * @param array $results
	 */
	final public static function setResults($results)
	{
		self::$results = $results;
	}

	/**
	 * @return array
	 */
	final public static function getResults()
	{
		return self::$results;
	}

	/**
	 * Display results
	 */
	final public static function showResults()
	{
		$results = self::getResults();
		asort($results);
		$best = key($results);
		$string = new CliColor;

		printf(
			"%-15s\t%-15s\t%-15s\t%-15s\n",
			'Test name', 'Repeats', 'Result', 'Performance'
		);

		foreach ($results as $name => $value) {
			$color = ($name === $best || $results[$best] === $value)
				? 'green' : 'red';

			$percent = self::getPercentDiff($results[$best], $value);

			$string->setColor($color);
			$string->setString($value);
			printf(
				"%-15s\t%-15s\t%-15s sec\t%-15s\n",
				$name, self::getRepeats(), $string, $percent . '%'
			);
		}
	}

	private static function getPercentDiff($best, $current)
	{
		$diff = $current - $best;
		$percent = $best / 100;
		$value = round($diff / $percent, 3);

		$result = new CliColor;

		if ($value > 0) {
			$result->setColor('red');
			$result->setstring("-$value");
		} else {
			$result->setColor('green');
			$result->setstring("+$value");
		}

		return $result;
	}

	/**
	 * Add result for further displaying
	 *
	 * @param string $name
	 * @param float $value
	 */
	final public static function addResult($name, $value)
	{
		self::$results[$name] = $value;
	}
}

{'fraction_non_alphanumeric': 0.17885442608105048, 'fraction_numerical': 0.01901743264659271, 'mean_word_length': 3.2810077519379846, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '5777632', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1523, 'n_words': 365}