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

Continuous benchmarking #194

Merged
merged 16 commits into from
Sep 8, 2022
62 changes: 62 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: benchmark
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
do-benchmark:
name: Benchmark runner
runs-on: ubuntu-latest
steps:
- name: Checkout folder to get test files
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- uses: actions/checkout@v3
if: github.event_name == 'push'
with:
fetch-depth: 0

- name: Rename checked out topojson package
run: mv topojson do_later_topojson

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install test dependencies
run: |
python -m pip install --upgrade pip
python -m pip install geopandas shapely numpy fire altair altair_saver okab

- name: Install latest topojson version from pypi
run: python -m pip install topojson
- name: Benchmark last released version!
run: python tests/benchmark_compute.py --version=last-released

- name: Install master repo topojson from git
run: python -m pip install git+https://github.com/mattijn/topojson.git --upgrade
- name: Benchmark version in github master!
run: python tests/benchmark_compute.py --version=master

- name: Rename moved topojson package
run: mv do_later_topojson topojson
- name: Benchmark this PR!
run: python tests/benchmark_compute.py --version=PR

- name: Create visz from benchmark results!
run: python tests/benchmark_visz.py

- name: Commit benchmark png
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "generate benchmark chart"
add: "tests/benchmark_chart.png --force"
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: test
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master

jobs:
do-explore:
name: Feedback runner
Expand All @@ -23,7 +23,7 @@ jobs:
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

do-test:
name: Test on Python
runs-on: ubuntu-latest
Expand All @@ -41,11 +41,11 @@ jobs:
- name: Install test dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flit codecov pytest flake8
python -m pip install flit codecov pytest flake8
- name: Install package dependencies
run: flit install --deps develop
run: flit install --deps develop
- name: Overrule shapely version from matrix
run: python -m pip install "shapely==${{ matrix.shapely-version }}"
run: python -m pip install "shapely==${{ matrix.shapely-version }}"
- name: Lint with flake8
run: flake8 topojson
continue-on-error: true
Expand Down
Binary file added tests/benchmark_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions tests/benchmark_compute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fire
import json
from time import process_time
from pathlib import Path
import geopandas
import topojson


def time_topology(data):
t_start = process_time()
_ = topojson.Topology(data)
t_stop = process_time()
return t_stop - t_start


def time_version(version):
"""
The following list contain files are being timed. The files filed should be able to
open by geopandas.read_file(). The characteristic of each file is as follow:
- nybb: a few detailed long linestrings
- naturalearth_lowres: similar alike linestrings, not too long
- mesh2d: many very short linestrings
"""
files_to_time = [
geopandas.datasets.get_path("nybb"),
geopandas.datasets.get_path("naturalearth_lowres"),
"tests/files_geojson/mesh2d.geojson",
]

# apply 3x timing to each file and collect result in list
list_times = []
for file_to_time in files_to_time:
gdf_data = geopandas.read_file(file_to_time)
for _ in range(3):
time_of_file = time_topology(gdf_data)
list_times.append(
{
"file": Path(file_to_time).stem,
"time": time_of_file,
"version": version,
}
)

# save timings within test folder, these files will not be kept, but only used to
# create a visualization in benchmark_visz.py
with open(f"tests/timings_{version}.json", "w") as f:
json.dump(list_times, f)


if __name__ == "__main__":

fire.Fire(time_version)
42 changes: 42 additions & 0 deletions tests/benchmark_visz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fire
from pathlib import Path
import altair as alt
import pandas as pd
from okab.saver import OkabSaver


def stats_to_visz():
# the following 3 versions are compared, namely the last released version on pypi
# the version that is currently on master in github and the version in the PR being
# processed.
versions = ["last-released", "master", "PR"]

# collect all timings and create a pandas dataframe
list_df = []
for version in versions:
fp_version = Path(f"tests/timings_{version}.json").resolve()
fp_version = fp_version.as_posix()
df_version = pd.read_json(fp_version, orient="records")
list_df.append(df_version)
df = pd.concat(list_df)

# parse to altair chart
chart = (
alt.Chart(df, title="timing of files (s) across version", height=150)
.mark_circle()
.encode(
x=alt.X("version:N", title=None),
y=alt.Y("time:Q", title=None, scale=alt.Scale(type="log")),
color="version:N",
column=alt.Column("file:N", title=None),
)
.resolve_scale(x="independent")
)

# save chart as png using okab as save method
chart.save("tests/benchmark_chart.png", method=OkabSaver, scale_factor=2)


if __name__ == "__main__":

fire.Fire(stats_to_visz)