Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test benchmarks and update validation logic #107

Merged
merged 45 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b0c2bd3
Test
SmetDenis Mar 28, 2024
bd6299d
Test
SmetDenis Mar 28, 2024
135d988
Test
SmetDenis Mar 28, 2024
bb401dc
Test
SmetDenis Mar 28, 2024
30c7f6a
Test
SmetDenis Mar 28, 2024
807c3e3
Test
SmetDenis Mar 28, 2024
2d59acc
Test
SmetDenis Mar 28, 2024
38db8f0
Test
SmetDenis Mar 28, 2024
cfaacf0
Test
SmetDenis Mar 28, 2024
655dc2e
Test
SmetDenis Mar 28, 2024
6335968
Test
SmetDenis Mar 28, 2024
aa90e80
Test
SmetDenis Mar 28, 2024
a9b0069
Test
SmetDenis Mar 28, 2024
fd7bad6
Test
SmetDenis Mar 28, 2024
96837d9
Test
SmetDenis Mar 28, 2024
156ca8f
Update Makefile
SmetDenis Mar 28, 2024
38a897e
Update Makefile
SmetDenis Mar 28, 2024
6eeea7c
Update Makefile
SmetDenis Mar 28, 2024
d6d83c6
Update Makefile
SmetDenis Mar 28, 2024
eec9e60
Test
SmetDenis Mar 28, 2024
ecbe114
Test
SmetDenis Mar 28, 2024
8e9290f
Update Makefile
SmetDenis Mar 28, 2024
72b76b1
Test
SmetDenis Mar 28, 2024
a4e61cf
Merge remote-tracking branch 'origin/readme-benchmarks' into readme-b…
SmetDenis Mar 28, 2024
3e41abf
Test
SmetDenis Mar 28, 2024
f3f38e0
Test
SmetDenis Mar 28, 2024
af97760
Test
SmetDenis Mar 28, 2024
c763ea9
Test
SmetDenis Mar 28, 2024
b61487c
Test
SmetDenis Mar 28, 2024
c21955b
Test
SmetDenis Mar 28, 2024
e2f3683
Test
SmetDenis Mar 28, 2024
c305b5e
Test
SmetDenis Mar 28, 2024
eb84a8d
Test
SmetDenis Mar 28, 2024
8a8b811
Test
SmetDenis Mar 28, 2024
b4cefa2
Improve test benchmarks and update validation logic
SmetDenis Mar 28, 2024
92c6d72
Update workflow file, remove PHP setup, enable Docker build
SmetDenis Mar 28, 2024
f4f52a2
Update workflow file, remove PHP setup, enable Docker build
SmetDenis Mar 28, 2024
155dc52
Update workflow file, remove PHP setup, enable Docker build
SmetDenis Mar 28, 2024
88029dc
Update workflow file, remove PHP setup, enable Docker build
SmetDenis Mar 28, 2024
62e61b2
Refactor code and optimize performance in CSV validation
SmetDenis Mar 28, 2024
36ab701
Refactor codebase and improve CSV validation speed
SmetDenis Mar 28, 2024
b08fc6b
Refactor codebase and improve CSV validation speed
SmetDenis Mar 28, 2024
75f9d09
Refactor codebase and improve CSV validation speed
SmetDenis Mar 28, 2024
06206fe
Rename GitHub action files and update workflow
SmetDenis Mar 28, 2024
28a39df
Rename GitHub action files and update workflow
SmetDenis Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,41 @@
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Benchmark
name: Stress Test

on:
pull_request:
branches:
- '*'
push:
branches:
- 'master'
workflow_run:
workflows: [ "Publish Docker" ]
types:
- completed

jobs:
benchmark:
stress-test:
name: Benchmark
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: jbzoo/csv-blueprint:master
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
tools: composer
extensions: opcache

- name: Build project
run: make build --no-print-directory

- name: Create random CSV files with 5M rows
- name: Create random huge CSV files
run: make bench-create-csv --no-print-directory

- name: Pull latest Docker image
run: docker pull ${{ env.DOCKER_IMAGE }}
- name: Building Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: jbzoo/csv-blueprint:local

- name: 🔥 Check 5M rows with Docker 🔥
- name: 🔥 Benchmark with Docker 🔥
run: make bench-docker --no-print-directory
44 changes: 4 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ jobs:
with:
php-version: 8.3
coverage: xdebug
tools: composer
extensions: ast, opcache
extensions: ast

- name: Build project
run: make build --no-print-directory
Expand Down Expand Up @@ -101,8 +100,7 @@ jobs:
with:
php-version: 8.1
coverage: none
tools: composer
extensions: ast, opcache
extensions: ast

- name: Install project
run: make build --no-print-directory
Expand Down Expand Up @@ -142,10 +140,9 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: highest
coverage: none
tools: composer
extensions: ast, opcache
extensions: ast

- name: Install project
run: make build --no-print-directory
Expand Down Expand Up @@ -185,7 +182,6 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer

- name: Build project in production mode
run: make build-prod --no-print-directory
Expand Down Expand Up @@ -218,8 +214,6 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: opcache

- name: Build project in production mode
run: make build-prod build-phar-file --no-print-directory
Expand Down Expand Up @@ -310,33 +304,3 @@ jobs:
csv: ./tests/fixtures/batch/*.csv
schema: ./tests/schemas/demo_*.yml
continue-on-error: true


benchmark:
name: Benchmark
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: jbzoo/csv-blueprint:master
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
tools: composer
extensions: opcache

- name: Build project
run: make build --no-print-directory

- name: Create random CSV files with 5M rows
run: make bench-create-csv --no-print-directory

- name: 🔥 Check 5M rows with PHP Binary 🔥
run: make bench-php --no-print-directory
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,42 @@
# @see https://github.com/JBZoo/Csv-Blueprint
#

name: Publish Docker
name: Publish

on:
release:
types: [ created ]

jobs:
phar:
name: Publish PHAR
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer

- name: Build project in production mode
run: make build-prod build-phar-file --no-print-directory

- name: 🎨 Test PHAR file
run: ./build/csv-blueprint.phar --ansi -vvv

- name: Upload PHAR to the release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
./build/csv-blueprint.phar

docker:
name: Publish Docker
runs-on: ubuntu-latest
Expand Down
47 changes: 0 additions & 47 deletions .github/workflows/release-phar.yml

This file was deleted.

67 changes: 24 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ ifneq (, $(wildcard ./vendor/jbzoo/codestyle/src/init.Makefile))
endif

DOCKER_IMAGE ?= jbzoo/csv-blueprint:local
CMD_VALIDATE := validate:csv --ansi -vvv
CMD_VALIDATE := validate:csv --ansi
BLUEPRINT := COLUMNS=300 time $(PHP_BIN) ./csv-blueprint $(CMD_VALIDATE)
BLUEPRINT_DOCKER := time docker run --rm --workdir=/parent-host -v .:/parent-host $(DOCKER_IMAGE) $(CMD_VALIDATE)
BENCH_BIN := time $(PHP_BIN) ./tests/Benchmarks/bench.php

VALID_CSV := --csv='./tests/fixtures/demo.csv'
VALID_SCHEMA := --schema='./tests/schemas/demo_valid.yml'
Expand Down Expand Up @@ -64,11 +63,11 @@ demo: ##@Demo Run demo via PHP binary
$(call title,"Demo - Valid CSV \(PHP binary\)")
@$(BLUEPRINT) $(VALID_CSV) $(VALID_SCHEMA)
$(call title,"Demo - Invalid CSV \(PHP binary\)")
@$(BLUEPRINT) $(INVALID_CSV) $(INVALID_SCHEMA)
@$(BLUEPRINT) $(INVALID_CSV) $(INVALID_SCHEMA) -vvv

REPORT ?= table
demo-github: ##@Demo Run demo invalid CSV for GitHub Actions
@$(BLUEPRINT) $(INVALID_CSV) $(INVALID_SCHEMA) --report=$(REPORT)
@$(BLUEPRINT) $(INVALID_CSV) $(INVALID_SCHEMA) -vvv --report=$(REPORT)


# Docker ###############################################################################################################
Expand All @@ -79,58 +78,40 @@ docker-build: ##@Docker (Re-)build Docker image

docker-demo: ##@Docker Run demo via Docker
$(call title,"Demo - Valid CSV \(via Docker\)")
@$(BLUEPRINT_DOCKER) $(VALID_CSV) $(VALID_SCHEMA)
@$(BLUEPRINT_DOCKER) $(VALID_CSV) $(VALID_SCHEMA) -vvv
$(call title,"Demo - Invalid CSV \(via Docker\)")
@$(BLUEPRINT_DOCKER) $(INVALID_CSV) $(INVALID_SCHEMA)
@$(BLUEPRINT_DOCKER) $(INVALID_CSV) $(INVALID_SCHEMA) -vvv

docker-in: ##@Docker Enter into Docker container
@docker run -it --entrypoint /bin/sh $(DOCKER_IMAGE)


# Benchmarks ###########################################################################################################
BENCH_ROWS ?= 5000000
BENCH_CSV := --csv=./build/bench/5_$(BENCH_ROWS)_header.csv
BENCH_SCHEMA_CELL := --schema=./tests/Benchmarks/benchmark-cell.yml
BENCH_SCHEMA_AGG := --schema=./tests/Benchmarks/benchmark-agg.yml
BENCH_COLS ?= 10
BENCH_ROWS_SRC ?= 1000
BENCH_CSV_PATH := ./build/bench/$(BENCH_COLS)_$(BENCH_ROWS_SRC)_000.csv
BENCH_CSV := --csv='$(BENCH_CSV_PATH)'
BENCH_SCHEMAS := --schema='./tests/Benchmarks/benchmark-*.yml'
BENCH_FLAGS := --debug --profile --report=text -vvv


bench-all: ##@Benchmarks Run all benchmarks
@make bench-create-csv
@make docker-build
@make bench-docker

bench-create-csv: ##@Benchmarks Create CSV file
$(call title,"PHP Benchmarks - Create $(BENCH_ROWS) CSV file")
$(call title,"Benchmark - Create CSV file")
@mkdir -pv ./build/bench/
$(BENCH_BIN) --add-header --columns=5 --rows=$(BENCH_ROWS) --ansi
ls -lah ./build/bench/*.csv;
@rm -fv ./build/bench/*.csv
@time bash ./tests/Benchmarks/create-csv.sh


bench-docker: ##@Benchmarks Run CSV file with Docker
$(call title,"PHP Benchmarks - CSV file with Docker")
$(call title,"Only one cell rule")
-$(BLUEPRINT_DOCKER) $(BENCH_CSV) $(BENCH_SCHEMA_CELL) --profile
$(call title,"Only one aggregation rule")
-$(BLUEPRINT_DOCKER) $(BENCH_CSV) $(BENCH_SCHEMA_AGG) --profile
$(call title,"Benchmark - CSV file with Docker")
-$(BLUEPRINT_DOCKER) $(BENCH_CSV) $(BENCH_SCHEMAS) $(BENCH_FLAGS)


bench-php: ##@Benchmarks Run CSV file with PHP binary
$(call title,"PHP Benchmarks - CSV file with PHP binary")
$(call title,"Only one cell rule")
-$(BLUEPRINT) $(BENCH_CSV) $(BENCH_SCHEMA_CELL) --profile
$(call title,"Only one aggregation rule")
-$(BLUEPRINT) $(BENCH_CSV) $(BENCH_SCHEMA_AGG) --profile


BENCH_ROWS_LIST := 100000 1000000
bench-prepare: ##@Benchmarks Create CSV files
$(call title,"PHP Benchmarks - Prepare CSV files")
exit 1; # Disabled for now. Enable if you need to generate CSV files.
@echo "Remove old CSV files"
mkdir -pv ./build/bench/
rm -fv ./build/bench/*.csv
@$(foreach rows,$(BENCH_ROWS_LIST), \
echo "Generate CSV: rows=$(rows)"; \
$(BENCH_BIN) -H --columns=1 --rows=$(rows) -q & \
$(BENCH_BIN) -H --columns=3 --rows=$(rows) -q & \
$(BENCH_BIN) -H --columns=5 --rows=$(rows) -q & \
$(BENCH_BIN) -H --columns=10 --rows=$(rows) -q & \
$(BENCH_BIN) -H --columns=20 --rows=$(rows) -q & \
wait; \
echo "Generate CSV: rows=$(rows) - done"; \
)
ls -lh ./build/bench/*.csv;
$(call title,"Benchmark - CSV file with PHP binary")
-$(BLUEPRINT) $(BENCH_CSV) $(BENCH_SCHEMAS) $(BENCH_FLAGS)
Loading