Skip to content

Commit

Permalink
#124 multiprocessing - php5 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 12, 2022
1 parent ac8752b commit 598af5f
Show file tree
Hide file tree
Showing 598 changed files with 60,447 additions and 9,064 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# top-most EditorConfig file
root = true
# 4 space indentation
[*]
end_of_line = lf
[*.php]
indent_style = tab
indent_size = 4
8 changes: 7 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/tool/ export-ignore
/composer.lock export-ignore
/composer.phar export-ignore
/.editorconfig export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
/.phpunit.result.cache export-ignore
Expand All @@ -20,5 +21,10 @@
/docs/** linguist-vendored
/tool/** linguist-vendored
/benchmark/** linguist-vendored

#
# do not replace lf by crlf
*.css text
*.php text
*.json text
text eol=lf

24 changes: 12 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
composer.phar
#composer.lock
phpunit.phar
/composer.phar
/composer.lock
/phpunit.phar
phpunit
phpdocumentor.sh
benchmark/
vendor/
test/debug.txt
.idea/
.git/
.phpunit.result.cache
xpath.txt
parsing.txt
test/color.php
test/*.json
/vendor/
/test/debug.txt
/test/*.php
/test/*.css
/.idea/
/.git/
/.phpunit.result.cache
/xpath.txt
/parsing.txt
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A CSS parser, beautifier and minifier written in PHP. It supports the following

- multibyte characters encoding
- sourcemap
- multiprocessing: process large CSS input very fast
- CSS Nesting module
- partially implemented CSS Syntax module level 3
- partial CSS validation
Expand Down Expand Up @@ -597,7 +598,7 @@ echo $renderer->render($parser->parse());
## Parser Options

- flatten_import: process @import directive and import the content into the css document. default to false.
- allow_duplicate_rules: allow duplicated rules. By default duplicate rules except @font-face are merged
- allow_duplicate_rules: allow duplicated rules. By default, duplicate rules except @font-face are merged
- allow_duplicate_declarations: allow duplicated declarations in the same rule.
- capture_errors: silently capture parse error if true, otherwise throw a parse exception. Default to true

Expand Down
3 changes: 2 additions & 1 deletion benchmark/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
'allow_duplicate_declarations' => true
];

$css = file_get_contents($argv[$compress ? 2 : 1]);
$filename = $argv[$compress ? 2 : 1];
$css = file_get_contents($filename);
2 changes: 1 addition & 1 deletion benchmark/parseast.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

$parser = (new Parser($css, $options));

$ast = $parser->getAst();
//$ast = $parser->getAst();
11 changes: 6 additions & 5 deletions benchmark/render.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/php
<?php

require __DIR__.'/../test/autoload.php';
require_once 'css.php';

use TBela\CSS\Renderer;

ob_start();
require_once 'parse.php';
ob_clean();

/**
* @var string $stylesheet
* @var string $css
* @var string $filename
* @var array $options
*/

echo (new Renderer($options))->render($stylesheet);
echo Renderer::fromString($css, $options, $options);
4 changes: 2 additions & 2 deletions benchmark/renderast.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
ob_clean();

/**
* @var stdClass $ast
* @var \TBela\CSS\Parser $parser
* @var array $options
*/

echo (new Renderer($options))->renderAst($ast);
echo (new Renderer($options))->renderAst($parser);
8 changes: 4 additions & 4 deletions bin/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ echo 'Rendering performance (Uncompressed)'
#
#benchmark "file${hpad}\tsize${hpad}\telement${hpad}\t\tsabber${hpad}\t\tast" "./render.php" "./renderSabberWorm.php" "./renderast.php"
# "element" involves an additional step to turn ast into element class instance, which is always slower and not fair ...
benchmark "file${hpad}\tsize${hpad}\t\tsabber${hpad}\t\tast" "./renderSabberWorm.php" "./renderast.php"
benchmark "file${hpad}\tsize${hpad}\t\tsabber${hpad}\t\tast\t\tRenderer::fromString" "./renderSabberWorm.php" "./renderast.php" "./render.php"

echo ""
echo 'Rendering performance (Compressed)'
#. ./render-compressed.sh
#
#benchmark "file${hpad}\tsize${hpad}\telement${hpad}\t\tsabber${hpad}\t\tast" "./render.php -c" "./renderSabberWorm.php -c" "./renderast.php -c"
# "element" involves an additional step to turn ast into element class instance, which is always slower and not fair ...
benchmark "file${hpad}\tsize${hpad}\t\tsabber${hpad}\t\tast" "./renderSabberWorm.php -c" "./renderast.php -c"
benchmark "file${hpad}\tsize${hpad}\t\tsabber${hpad}\t\tast\t\tRenderer::fromString" "./renderSabberWorm.php -c" "./renderast.php -c" "./render.php -c"

echo ""
#pad="\t\t"
Expand All @@ -225,12 +225,12 @@ echo 'Size (Uncompressed)'
#
#getsize "file\t${hpad}size${hpad}\telement${hpad}\t\tsabber${hpad}\t\tast" "./render.php" "./renderSabberWorm.php" "./renderast.php"
# "element" involves an additional step to turn ast into element class instance, which is always slower and not fair ...
getsize "file\t${hpad}size${hpad}\t\tsabber${hpad}\t\tast" "./renderSabberWorm.php" "./renderast.php"
getsize "file\t${hpad}size${hpad}\t\tsabber${hpad}\t\tast\t\tRenderer::fromString" "./renderSabberWorm.php" "./renderast.php" "./render.php"

echo ""
echo 'Size (Compressed)'
# . ./compressed-size.sh
#
#getsize "file\t${hpad}size${hpad}\telement${hpad}\t\tsabber${hpad}\t\tast" "./render.php -c" "./renderSabberWorm.php -c" "./renderast.php -c"
# "element" involves an additional step to turn ast into element class instance, which is always slower and not fair ...
getsize "file\t${hpad}size${hpad}\t\tsabber${hpad}\t\tast" "./renderSabberWorm.php -c" "./renderast.php -c"
getsize "file\t${hpad}size${hpad}\t\tsabber${hpad}\t\tast\t\tRenderer::fromString" "./renderSabberWorm.php -c" "./renderast.php -c" "./render.php -c"
56 changes: 40 additions & 16 deletions bin/runtest.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/bin/sh
# # to run run a particular test, give the file name without extension as a parameter
## $ ./runtest.sh Render Path Ast
# to exclude specific tests, prepend '-' in front of the test name
## $ ./runtest.sh -Minify -Ast
## ./runtest.sh Render Ast Sourcemap
# to run all specific tests, prepend '-' in front of the test name to exclude
## ./runtest.sh -Minify -Ast -Sourcemap
# to run all the tests with no argument
## ./runtest.sh
#set -x
##
DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "$DIR/../test/"
[ ! -f "../phpunit-5.phar" ] &&
wget -O ../phpunit-5.phar https://phar.phpunit.de/phpunit-5.phar &&
chmod +x ../phpunit-5.phar

php56=`command -v php5.6 2>/dev/null`

if [ -z "$php56" ]; then
Expand All @@ -29,7 +27,7 @@ if [ -z "$php56" ]; then
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update -y
sudo apt-get install -y php5.6 php7.4
sudo apt-get install -y php5.6

fi

Expand All @@ -48,6 +46,12 @@ fi
# ;;
# esac
fi
if [ ! -f "../vendor/bin/phpunit" ]; then
echo "please go to "$(dirname "$DIR")" and run 'composer install'"
exit 1
fi

unset DIR
#
#
#../phpunit.phar --bootstrap autoload.php src/*.php
Expand All @@ -60,10 +64,26 @@ fail() {
exit 1
}

run() {

#
# set -x
$php56 -dmemory_limit=512M ../vendor/bin/phpunit -v --enforce-time-limit --colors=always --bootstrap autoload.php --testdox --fail-on-risky "$@"
# set +x
}

testName() {

fname=$(basename "$1" | awk -F . '{print $1}')

# strip the Test suffix
echo ""${fname%Test}
}

#
#
cd ../test
pwd
#pwd
#
#
if [ $# -gt 0 ]; then
Expand All @@ -74,30 +94,34 @@ if [ $# -gt 0 ]; then
for file in $(ls src/*.php); do
fname=$(basename "$file" | awk -F . '{print $1}')

# strip the Test suffix
fname=""${fname%Test}

case "$@" in
*-$fname*) continue ;;
*) $php56 -dmemory_limit=256M ../phpunit-5.phar --colors=always --bootstrap autoload.php --testdox "$file" || fail "$file" ;;
*) run "$file" || fail "$file" ;;
esac
done
;;
*)
for file in $(ls src/*.php); do

fname=$(basename "$file" | awk -F . '{print $1}')
# strip the Test suffix
fname=""${fname%Test}

case "$@" in
*$fname*)
echo "$fname"
*$fname*)

$php56 -dmemory_limit=256M ../phpunit-5.phar --colors=always --bootstrap autoload.php --testdox "$file" || fail "$file"
run "$file" || fail "$file"
;;
esac
done
;;
esac
else
# no argument
for file in $(ls src/*.php); do
$php56 -dmemory_limit=256M ../phpunit-5.phar --colors=always --bootstrap autoload.php --testdox "$file" || fail "$file"
done
# no argument
for file in $(ls src/*.php); do
run "$file" || fail "$file"
done
fi
Loading

0 comments on commit 598af5f

Please sign in to comment.