mirror of
https://github.com/django-components/django-components.git
synced 2025-08-05 14:57:59 +00:00
Compare commits
469 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
09e96d92d6 | ||
![]() |
df8c6ab1a4 | ||
![]() |
10e1a25b26 | ||
![]() |
9e280f2e61 | ||
![]() |
de1ebcd071 | ||
![]() |
740a8c5f1c | ||
![]() |
7a260f7e47 | ||
![]() |
6772736f4c | ||
![]() |
8246f908bf | ||
![]() |
5d7e235725 | ||
![]() |
2a44fbec27 | ||
![]() |
f4347dd9d9 | ||
![]() |
65373ec3e8 | ||
![]() |
81c0d419b4 | ||
![]() |
672811b8b4 | ||
![]() |
f8c8292441 | ||
![]() |
8cba8702a3 | ||
![]() |
fb4b654433 | ||
![]() |
5f8ec71358 | ||
![]() |
f15f1e967a | ||
![]() |
b7b0d250c4 | ||
![]() |
0c7e17d8cf | ||
![]() |
514b8206b5 | ||
![]() |
bcc7bac48d | ||
![]() |
39e9ee0dc3 | ||
![]() |
df7f94cb2d | ||
![]() |
9a4f835201 | ||
![]() |
59e5fb3b38 | ||
![]() |
c692b7a310 | ||
![]() |
007009a480 | ||
![]() |
f8e2721244 | ||
![]() |
77fd149346 | ||
![]() |
055dd07694 | ||
![]() |
e7883d0b54 | ||
![]() |
64322a7b84 | ||
![]() |
b021b54ad4 | ||
![]() |
212336c99a | ||
![]() |
8ceb143fb3 | ||
![]() |
15669a2fb1 | ||
![]() |
10a9e555c0 | ||
![]() |
4d9c814e32 | ||
![]() |
68089daefb | ||
![]() |
b0da3b166d | ||
![]() |
5e34ec28cf | ||
![]() |
b0ef1f2a4c | ||
![]() |
14a8358b08 | ||
![]() |
b09c83b128 | ||
![]() |
6e86851894 | ||
![]() |
b9e8b8e569 | ||
![]() |
1db72b6e96 | ||
![]() |
cd1643ad23 | ||
![]() |
6d754acb99 | ||
![]() |
50d71b6187 | ||
![]() |
bdfe966919 | ||
![]() |
d537ba1ee5 | ||
![]() |
06c89cf9e8 | ||
![]() |
3fc96daa9b | ||
![]() |
458e1894db | ||
![]() |
2350a6b6c4 | ||
![]() |
291b97cfd1 | ||
![]() |
6a8fc27bad | ||
![]() |
328b55ff29 | ||
![]() |
136a7a591c | ||
![]() |
4d056b2c49 | ||
![]() |
8209614fc2 | ||
![]() |
7bece01024 | ||
![]() |
49f0c05bf6 | ||
![]() |
831db00598 | ||
![]() |
09bcf8dbcc | ||
![]() |
efe5eb0ba5 | ||
![]() |
ace29db9ac | ||
![]() |
04737412d9 | ||
![]() |
b2e053118b | ||
![]() |
7b24b86f4a | ||
![]() |
468abaf92f | ||
![]() |
593c66db7f | ||
![]() |
04f79a6e6b | ||
![]() |
eceebb9696 | ||
![]() |
46e524e37d | ||
![]() |
abc6be343e | ||
![]() |
87eb1f8479 | ||
![]() |
c5a4a81852 | ||
![]() |
09cb8714cc | ||
![]() |
8677ee7941 | ||
![]() |
fa9ae9892f | ||
![]() |
bb129aefab | ||
![]() |
7df8019544 | ||
![]() |
42eb6f93ae | ||
![]() |
dfb90c4005 | ||
![]() |
26845fe60a | ||
![]() |
e8eb296897 | ||
![]() |
6aec2d23dc | ||
![]() |
7884705869 | ||
![]() |
d7fee43dd9 | ||
![]() |
55b1c8bc62 | ||
![]() |
bae0f28813 | ||
![]() |
2e08af9a13 | ||
![]() |
046569e16d | ||
![]() |
6ff2d78a2f | ||
![]() |
223fc2c68c | ||
![]() |
e054a68715 | ||
![]() |
d514694788 | ||
![]() |
f069255b64 | ||
![]() |
7a49a7806c | ||
![]() |
0718b4cac6 | ||
![]() |
4f15ad8360 | ||
![]() |
49ad23b21d | ||
![]() |
71db46d5ca | ||
![]() |
79c42da2f9 | ||
![]() |
b6b574d875 | ||
![]() |
0d05ef4cb2 | ||
![]() |
53d80684bb | ||
![]() |
2eb9f5d43d | ||
![]() |
1bb7c3fdfe | ||
![]() |
f80457e964 | ||
![]() |
a96f5fdd2f | ||
![]() |
b83eaefcd0 | ||
![]() |
9dda6f8c16 | ||
![]() |
5fb0c9032b | ||
![]() |
e5126b04ef | ||
![]() |
77178190ed | ||
![]() |
d7e6d5a961 | ||
![]() |
406828c51a | ||
![]() |
fcc8d71dca | ||
![]() |
ccf02fa316 | ||
![]() |
5f4fbe76e5 | ||
![]() |
661413d4a9 | ||
![]() |
e64cd197c1 | ||
![]() |
ccd8e26956 | ||
![]() |
6aa2a39fe9 | ||
![]() |
26078d5340 | ||
![]() |
2dacac1f43 | ||
![]() |
6253042e9e | ||
![]() |
1049c08324 | ||
![]() |
ca4e7f7f8b | ||
![]() |
b13f859d7b | ||
![]() |
330578a2c7 | ||
![]() |
d4d834256a | ||
![]() |
28b61c1609 | ||
![]() |
c69980493d | ||
![]() |
bf7a204e92 | ||
![]() |
e74e1241ac | ||
![]() |
76a888aa11 | ||
![]() |
bb9e8e0bad | ||
![]() |
95e5df9d3c | ||
![]() |
c5c7b7a52c | ||
![]() |
3eb148754a | ||
![]() |
b8dbf89612 | ||
![]() |
d33a1b87aa | ||
![]() |
456e011f9b | ||
![]() |
6a452b285e | ||
![]() |
7b15ea9ea8 | ||
![]() |
59f82307ae | ||
![]() |
89db10a643 | ||
![]() |
5704bc86a1 | ||
![]() |
a5a93e9bbb | ||
![]() |
a368786267 | ||
![]() |
dbe8dc074d | ||
![]() |
2b69980845 | ||
![]() |
519529d4e4 | ||
![]() |
c8002d241a | ||
![]() |
b949e4a6ec | ||
![]() |
b49002b545 | ||
![]() |
912d8e8074 | ||
![]() |
4c90948606 | ||
![]() |
e0b718c314 | ||
![]() |
eed15d32ab | ||
![]() |
68ede4f662 | ||
![]() |
bd1a4fd65d | ||
![]() |
56846c5fc4 | ||
![]() |
8cf42dd20f | ||
![]() |
2905c6980a | ||
![]() |
0fad34f271 | ||
![]() |
6e7e5cd162 | ||
![]() |
a69c2329b0 | ||
![]() |
c650e7f3a5 | ||
![]() |
fc026cbd99 | ||
![]() |
06cad2ec64 | ||
![]() |
61528ef0ad | ||
![]() |
3148557e91 | ||
![]() |
ad402fc619 | ||
![]() |
d37291a3b6 | ||
![]() |
5b01d6c3c6 | ||
![]() |
07f747d705 | ||
![]() |
cc249022c4 | ||
![]() |
1319a95627 | ||
![]() |
613dfea379 | ||
![]() |
9ede779fa3 | ||
![]() |
b6994e9ad3 | ||
![]() |
ef15117459 | ||
![]() |
625c1a4735 | ||
![]() |
c8f9b35f2e | ||
![]() |
077ba59ce1 | ||
![]() |
0417e369f7 | ||
![]() |
2213f43c89 | ||
![]() |
1074ebe2f1 | ||
![]() |
225f45d0b8 | ||
![]() |
ec5cc278a4 | ||
![]() |
e0e9501dca | ||
![]() |
fd12bb47ab | ||
![]() |
bd703ead4b | ||
![]() |
084b6c7f34 | ||
![]() |
dfb675343e | ||
![]() |
2fedd9d0e2 | ||
![]() |
db324e291f | ||
![]() |
1dfec8fc6d | ||
![]() |
9f9b1f7232 | ||
![]() |
bb5de86b69 | ||
![]() |
a49f5e51dd | ||
![]() |
3555411f1e | ||
![]() |
0ed46e4d30 | ||
![]() |
637e143538 | ||
![]() |
fdd29baa65 | ||
![]() |
2499126d1f | ||
![]() |
7e74831599 | ||
![]() |
5e263ec143 | ||
![]() |
ce140ae2c2 | ||
![]() |
57d035c67d | ||
![]() |
1b8122312e | ||
![]() |
e184834e93 | ||
![]() |
d523a97fcc | ||
![]() |
61a70e7705 | ||
![]() |
e35c4e24fb | ||
![]() |
53adc9e18a | ||
![]() |
184c3e4c6c | ||
![]() |
22dac99e4e | ||
![]() |
a6455d70f6 | ||
![]() |
9f68f0f1a1 | ||
![]() |
f07818fc7d | ||
![]() |
48dd3b7a5a | ||
![]() |
b5098cfe75 | ||
![]() |
74ed201b69 | ||
![]() |
74d21b87e5 | ||
![]() |
14f070c72c | ||
![]() |
05246625b3 | ||
![]() |
46b49336ba | ||
![]() |
e00a305e00 | ||
![]() |
328309a81c | ||
![]() |
1e71f3d656 | ||
![]() |
42818ad6ff | ||
![]() |
3544402215 | ||
![]() |
2472c2ad33 | ||
![]() |
25e99854c0 | ||
![]() |
eb122ff8cf | ||
![]() |
9d51432262 | ||
![]() |
bbc8af415e | ||
![]() |
09eb2d27a5 | ||
![]() |
6f13cb9183 | ||
![]() |
a7ed0711fc | ||
![]() |
884d4ffbdd | ||
![]() |
9b27515a36 | ||
![]() |
75510c5793 | ||
![]() |
04dd0c21ba | ||
![]() |
2037ed20b7 | ||
![]() |
30f3739499 | ||
![]() |
390211b86e | ||
![]() |
ab75cfdb8f | ||
![]() |
73e94b6714 | ||
![]() |
d0a42a2698 | ||
![]() |
a2aa743947 | ||
![]() |
293b933aaa | ||
![]() |
173537ef36 | ||
![]() |
f54f3ccb0b | ||
![]() |
c034b7da65 | ||
![]() |
0f41a62592 | ||
![]() |
107284f474 | ||
![]() |
944bef2d95 | ||
![]() |
8b8f120480 | ||
![]() |
0c00f25618 | ||
![]() |
a5dd96fb1f | ||
![]() |
c4894e9d7f | ||
![]() |
fca88f4a32 | ||
![]() |
a8e062eb31 | ||
![]() |
386c7339dc | ||
![]() |
40e90df098 | ||
![]() |
21631c1cd5 | ||
![]() |
da44f36309 | ||
![]() |
b26d476ce9 | ||
![]() |
9df6c54f9a | ||
![]() |
511aa527cd | ||
![]() |
ff8c3698f2 | ||
![]() |
547c809bf2 | ||
![]() |
1c2d773ccc | ||
![]() |
bad8680e9a | ||
![]() |
c446975f94 | ||
![]() |
439fcf68e0 | ||
![]() |
99067c4b20 | ||
![]() |
ebfb26121a | ||
![]() |
8e7acd82be | ||
![]() |
12a64f8e41 | ||
![]() |
d3d2d0ab08 | ||
![]() |
3a139127cd | ||
![]() |
b18617c5a0 | ||
![]() |
86dcd89ac4 | ||
![]() |
3ae91f4767 | ||
![]() |
b9eff499c0 | ||
![]() |
4ea6d33e3b | ||
![]() |
3a1233ceb2 | ||
![]() |
d8c9ca922c | ||
![]() |
8f986a16ee | ||
![]() |
8e91dcd9ea | ||
![]() |
e7e5c633df | ||
![]() |
b846188f93 | ||
![]() |
4d35bc97a2 | ||
![]() |
cff252c566 | ||
![]() |
67c8aadaa8 | ||
![]() |
d38376edce | ||
![]() |
009b6603c7 | ||
![]() |
33ce425524 | ||
![]() |
19521c2d5a | ||
![]() |
30beeabfa4 | ||
![]() |
df3a6b7875 | ||
![]() |
3418a527e0 | ||
![]() |
23af4befda | ||
![]() |
5018450fca | ||
![]() |
3b8fc9e701 | ||
![]() |
6b5b2fc5ee | ||
![]() |
498847f415 | ||
![]() |
131c03f416 | ||
![]() |
7dfcb447c4 | ||
![]() |
81ac59f7fb | ||
![]() |
d5e45125dc | ||
![]() |
f36581ed86 | ||
![]() |
dcd4203eea | ||
![]() |
0adf8fa7db | ||
![]() |
314ec77d3d | ||
![]() |
1f7e28db22 | ||
![]() |
77a9099235 | ||
![]() |
9a1644f293 | ||
![]() |
e75d613461 | ||
![]() |
bb3b53239d | ||
![]() |
8b5579d2be | ||
![]() |
471760e569 | ||
![]() |
5535f3bad8 | ||
![]() |
bd2610ca5b | ||
![]() |
ad3c4643c5 | ||
![]() |
c2fb77f715 | ||
![]() |
e9e6bdf243 | ||
![]() |
e21538d3de | ||
![]() |
4e365c826f | ||
![]() |
691443a0a8 | ||
![]() |
fdfdc72ed2 | ||
![]() |
58d4c78671 | ||
![]() |
3cf586a974 | ||
![]() |
8f9d675097 | ||
![]() |
5d01f203ab | ||
![]() |
eb3f72ee0d | ||
![]() |
be4d744d64 | ||
![]() |
33130c749e | ||
![]() |
137e36e96d | ||
![]() |
b76d8b36c0 | ||
![]() |
e243050eff | ||
![]() |
cf336e1a04 | ||
![]() |
e1881e5af7 | ||
![]() |
f15892b9e8 | ||
![]() |
de99abf6bf | ||
![]() |
fe128053c9 | ||
![]() |
61515b3454 | ||
![]() |
af179f3a1f | ||
![]() |
48bae51ab9 | ||
![]() |
bb61ff42eb | ||
![]() |
9f92419737 | ||
![]() |
2767655a89 | ||
![]() |
57ec784df0 | ||
![]() |
60fc86386e | ||
![]() |
444f2dceb5 | ||
![]() |
5d9f0ddf91 | ||
![]() |
f4820c09f6 | ||
![]() |
d55dfaf817 | ||
![]() |
1b3b514b29 | ||
![]() |
e469cb362e | ||
![]() |
3d9d43639c | ||
![]() |
c7aba40252 | ||
![]() |
f52f12579b | ||
![]() |
de32d449d9 | ||
![]() |
da54d97343 | ||
![]() |
21121f149d | ||
![]() |
96f48bc013 | ||
![]() |
588053803d | ||
![]() |
e105500350 | ||
![]() |
f01ee1fe8a | ||
![]() |
bafa9f7cc5 | ||
![]() |
bfd917fa20 | ||
![]() |
3d187d7aba | ||
![]() |
b69c6e6624 | ||
![]() |
55bcc11f50 | ||
![]() |
292889391b | ||
![]() |
0b65761fce | ||
![]() |
d407a8cd13 | ||
![]() |
0c3a154a27 | ||
![]() |
e8d1c32d84 | ||
![]() |
6ccc2fe0f4 | ||
![]() |
914576e681 | ||
![]() |
92f5497c74 | ||
![]() |
ace9194733 | ||
![]() |
c30da64c9e | ||
![]() |
c5df006afb | ||
![]() |
dc16b97a09 | ||
![]() |
0a045d60b4 | ||
![]() |
c8cedb46c2 | ||
![]() |
3698fb5e47 | ||
![]() |
f71ff3bcfb | ||
![]() |
f908197850 | ||
![]() |
a047908189 | ||
![]() |
873aac7097 | ||
![]() |
61ee215d88 | ||
![]() |
ea9bf9ac82 | ||
![]() |
921f0780c4 | ||
![]() |
f526eaece9 | ||
![]() |
44d87faa3b | ||
![]() |
bf5f71bbee | ||
![]() |
7ed4fd88f9 | ||
![]() |
8cd4b03286 | ||
![]() |
d3c5c535e0 | ||
![]() |
b54eb4b38a | ||
![]() |
1d5ea4c0f1 | ||
![]() |
93a18deb21 | ||
![]() |
a21acee8a7 | ||
![]() |
827d04d865 | ||
![]() |
d785e4847a | ||
![]() |
17e85fbeab | ||
![]() |
ba0f9e65e9 | ||
![]() |
a79b24b692 | ||
![]() |
6c2a687d69 | ||
![]() |
3bbd4326e6 | ||
![]() |
ab037f24b0 | ||
![]() |
5e8770c720 | ||
![]() |
81c02ddaa7 | ||
![]() |
203d29f511 | ||
![]() |
1e4b556b4d | ||
![]() |
8e2428ebd0 | ||
![]() |
aa540cbc4a | ||
![]() |
2c3a4255bb | ||
![]() |
7ec709c3f2 | ||
![]() |
0e9d5287f8 | ||
![]() |
e398987b3b | ||
![]() |
4559899513 | ||
![]() |
a702768573 | ||
![]() |
8891041a27 | ||
![]() |
2b5bfa9eeb | ||
![]() |
d94a459c8d | ||
![]() |
b99e32e9d5 | ||
![]() |
9b611f78fc | ||
![]() |
329a398c61 | ||
![]() |
57f89e2dcf | ||
![]() |
b905299405 | ||
![]() |
66cae95ef2 | ||
![]() |
e7ff01dec5 | ||
![]() |
6de3018f2e | ||
![]() |
071bb6895f | ||
![]() |
8ac9dd6e86 | ||
![]() |
0d38730332 | ||
![]() |
715bf7d447 | ||
![]() |
8fcb84c002 | ||
![]() |
303d4db7ba | ||
![]() |
fe67d90547 | ||
![]() |
296da4a1e8 | ||
![]() |
ed26aec18d | ||
![]() |
6ceda99ab5 | ||
![]() |
0985c8efc6 | ||
![]() |
1e1b84a3a6 | ||
![]() |
081ef1b85f | ||
![]() |
2e33f160a9 | ||
![]() |
8f950cddaa | ||
![]() |
dd00be65ff | ||
![]() |
b2ce52dc53 | ||
![]() |
ca3a247bb3 | ||
![]() |
d44a4ae177 | ||
![]() |
f768a3cf55 |
372 changed files with 89258 additions and 13124 deletions
385
.asv/results/benchmarks.json
Normal file
385
.asv/results/benchmarks.json
Normal file
|
@ -0,0 +1,385 @@
|
|||
{
|
||||
"Components vs Django.peakmem_render_lg_first": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - large - first render (mem)\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n setup=lambda renderer: setup_templating_memory_benchmark(renderer, \"lg\", \"first\", \"isolated\"),\n )\n def peakmem_render_lg_first(self, renderer: TemplatingRenderer):\n do_render()\n\nsetup=lambda renderer: setup_templating_memory_benchmark(renderer, \"lg\", \"first\", \"isolated\"),",
|
||||
"name": "Components vs Django.peakmem_render_lg_first",
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - first render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "301c396f017f45a5b3f71e85df58d15f54153fcfd951af7ef424641d4b31b528"
|
||||
},
|
||||
"Components vs Django.peakmem_render_lg_subsequent": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - large - second render (mem)\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n setup=lambda renderer: setup_templating_memory_benchmark(renderer, \"lg\", \"subsequent\", \"isolated\"),\n )\n def peakmem_render_lg_subsequent(self, renderer: TemplatingRenderer):\n do_render()\n\nsetup=lambda renderer: setup_templating_memory_benchmark(renderer, \"lg\", \"subsequent\", \"isolated\"),",
|
||||
"name": "Components vs Django.peakmem_render_lg_subsequent",
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - second render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "9a44e9999ef3ef42ea7e01323727490244febb43d66a87a4d8f88c6b8a133b8b"
|
||||
},
|
||||
"Components vs Django.peakmem_render_sm_first": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - small - first render (mem)\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n setup=lambda renderer: setup_templating_memory_benchmark(renderer, \"sm\", \"first\", \"isolated\"),\n )\n def peakmem_render_sm_first(self, renderer: TemplatingRenderer):\n do_render()\n\nsetup=lambda renderer: setup_templating_memory_benchmark(renderer, \"sm\", \"first\", \"isolated\"),",
|
||||
"name": "Components vs Django.peakmem_render_sm_first",
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - first render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "e93b7a5193681c883edf85bdb30b1bc0821263bf51033fdcee215b155085e036"
|
||||
},
|
||||
"Components vs Django.peakmem_render_sm_subsequent": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - small - second render (mem)\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n setup=lambda renderer: setup_templating_memory_benchmark(renderer, \"sm\", \"subsequent\", \"isolated\"),\n )\n def peakmem_render_sm_subsequent(self, renderer: TemplatingRenderer):\n do_render()\n\nsetup=lambda renderer: setup_templating_memory_benchmark(renderer, \"sm\", \"subsequent\", \"isolated\"),",
|
||||
"name": "Components vs Django.peakmem_render_sm_subsequent",
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - second render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "b46e0820b18950aa7cc5e61306ff3425b76b4da9dca42d64fae5b1d25c6c9026"
|
||||
},
|
||||
"Components vs Django.timeraw_render_lg_first": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - large - first render\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n include_in_quick_benchmark=True,\n )\n def timeraw_render_lg_first(self, renderer: TemplatingRenderer):\n return prepare_templating_benchmark(renderer, \"lg\", \"first\", \"isolated\")",
|
||||
"min_run_count": 2,
|
||||
"name": "Components vs Django.timeraw_render_lg_first",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - first render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "be3bf6236960046a028b6ea007aad28b2337fc2b906b8ce317a09a5d4f1a6193",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"Components vs Django.timeraw_render_lg_subsequent": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - large - second render\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n )\n def timeraw_render_lg_subsequent(self, renderer: TemplatingRenderer):\n return prepare_templating_benchmark(renderer, \"lg\", \"subsequent\", \"isolated\")",
|
||||
"min_run_count": 2,
|
||||
"name": "Components vs Django.timeraw_render_lg_subsequent",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - second render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "b98221c11a0ee6e9de0778d416d31b9dd514a674d9017a2bb9b2fc1cd0f01920",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"Components vs Django.timeraw_render_sm_first": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - small - first render\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n )\n def timeraw_render_sm_first(self, renderer: TemplatingRenderer):\n return prepare_templating_benchmark(renderer, \"sm\", \"first\", \"isolated\")",
|
||||
"min_run_count": 2,
|
||||
"name": "Components vs Django.timeraw_render_sm_first",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - first render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "f1fc17e4a31c71f4d9265f1122da52e7cf57addb4dfa02606e303b33d6431b9b",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"Components vs Django.timeraw_render_sm_subsequent": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"render - small - second render\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n )\n def timeraw_render_sm_subsequent(self, renderer: TemplatingRenderer):\n return prepare_templating_benchmark(renderer, \"sm\", \"subsequent\", \"isolated\")",
|
||||
"min_run_count": 2,
|
||||
"name": "Components vs Django.timeraw_render_sm_subsequent",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - second render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "6fce1cd85a9344fee383b40a22f27862120b9488a628420625592dc14e0307d3",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"Components vs Django.timeraw_startup_lg": {
|
||||
"code": "class DjangoComponentsVsDjangoTests:\n @benchmark(\n pretty_name=\"startup - large\",\n group_name=DJC_VS_DJ_GROUP,\n number=1,\n rounds=5,\n params={\n \"renderer\": [\"django\", \"django-components\"],\n },\n )\n def timeraw_startup_lg(self, renderer: TemplatingRenderer):\n return prepare_templating_benchmark(renderer, \"lg\", \"startup\", \"isolated\")",
|
||||
"min_run_count": 2,
|
||||
"name": "Components vs Django.timeraw_startup_lg",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"renderer"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'django'",
|
||||
"'django-components'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "startup - large",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "53151821c128ad0ecfb0707fff3146e1abd8d0bcfa301aa056b5d3fae3d793e2",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"Other.timeraw_import_time": {
|
||||
"code": "class OtherTests:\n @benchmark(\n pretty_name=\"import time\",\n group_name=OTHER_GROUP,\n number=1,\n rounds=5,\n )\n def timeraw_import_time(self):\n return prepare_templating_benchmark(\"django-components\", \"lg\", \"startup\", \"isolated\", imports_only=True)",
|
||||
"min_run_count": 2,
|
||||
"name": "Other.timeraw_import_time",
|
||||
"number": 1,
|
||||
"param_names": [],
|
||||
"params": [],
|
||||
"pretty_name": "import time",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "a0a1c1c0db22509410b946d0d4384b52ea4a09b47b6048d7d1cfb89b0c7fe5c3",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"isolated vs django modes.peakmem_render_lg_first": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - large - first render (mem)\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n setup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"lg\",\n \"first\",\n context_mode,\n ),\n )\n def peakmem_render_lg_first(self, context_mode: DjcContextMode):\n do_render()\n\nsetup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"lg\",\n \"first\",\n context_mode,\n),",
|
||||
"name": "isolated vs django modes.peakmem_render_lg_first",
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - first render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "c4bf0016d48d210f08b8db733b57c7dcba1cebbf548c458b93b86ace387067e9"
|
||||
},
|
||||
"isolated vs django modes.peakmem_render_lg_subsequent": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - large - second render (mem)\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n setup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"lg\",\n \"subsequent\",\n context_mode,\n ),\n )\n def peakmem_render_lg_subsequent(self, context_mode: DjcContextMode):\n do_render()\n\nsetup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"lg\",\n \"subsequent\",\n context_mode,\n),",
|
||||
"name": "isolated vs django modes.peakmem_render_lg_subsequent",
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - second render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "65bb1b8586487197a79bb6073e4c71642877b845b6eb42d1bd32398299daffbf"
|
||||
},
|
||||
"isolated vs django modes.peakmem_render_sm_first": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - small - first render (mem)\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n setup=lambda context_mode: setup_templating_memory_benchmark(\"django-components\", \"sm\", \"first\", context_mode),\n )\n def peakmem_render_sm_first(self, context_mode: DjcContextMode):\n do_render()\n\nsetup=lambda context_mode: setup_templating_memory_benchmark(\"django-components\", \"sm\", \"first\", context_mode),",
|
||||
"name": "isolated vs django modes.peakmem_render_sm_first",
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - first render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "c51b91fc583295776062822225e720b5ed71aef9c9288217c401c54283c62840"
|
||||
},
|
||||
"isolated vs django modes.peakmem_render_sm_subsequent": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - small - second render (mem)\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n setup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"sm\",\n \"subsequent\",\n context_mode,\n ),\n )\n def peakmem_render_sm_subsequent(self, context_mode: DjcContextMode):\n do_render()\n\nsetup=lambda context_mode: setup_templating_memory_benchmark(\n \"django-components\",\n \"sm\",\n \"subsequent\",\n context_mode,\n),",
|
||||
"name": "isolated vs django modes.peakmem_render_sm_subsequent",
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - second render (mem)",
|
||||
"type": "peakmemory",
|
||||
"unit": "bytes",
|
||||
"version": "54d747fb8f40179b7ff3d2fc49eb195909ad1c880b5ef7b82f82742b27b67260"
|
||||
},
|
||||
"isolated vs django modes.timeraw_render_lg_first": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - large - first render\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n )\n def timeraw_render_lg_first(self, context_mode: DjcContextMode):\n return prepare_templating_benchmark(\"django-components\", \"lg\", \"first\", context_mode)",
|
||||
"min_run_count": 2,
|
||||
"name": "isolated vs django modes.timeraw_render_lg_first",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - first render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "f94af83427c6346f88f8785a3cd2fc42415ac5a9fbbdb7de71d27e22e6a81699",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"isolated vs django modes.timeraw_render_lg_subsequent": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - large - second render\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n )\n def timeraw_render_lg_subsequent(self, context_mode: DjcContextMode):\n return prepare_templating_benchmark(\"django-components\", \"lg\", \"subsequent\", context_mode)",
|
||||
"min_run_count": 2,
|
||||
"name": "isolated vs django modes.timeraw_render_lg_subsequent",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - large - second render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "9f7c2fde6b33f0451a1794ed903c48d96cd7822f67da502cec36fe8e977c2414",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"isolated vs django modes.timeraw_render_sm_first": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - small - first render\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n )\n def timeraw_render_sm_first(self, context_mode: DjcContextMode):\n return prepare_templating_benchmark(\"django-components\", \"sm\", \"first\", context_mode)",
|
||||
"min_run_count": 2,
|
||||
"name": "isolated vs django modes.timeraw_render_sm_first",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - first render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "d15ca68909d7f1f43ff16863befb6f42681f17461417fc0069eefd6db3569296",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"isolated vs django modes.timeraw_render_sm_subsequent": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"render - small - second render\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n )\n def timeraw_render_sm_subsequent(self, context_mode: DjcContextMode):\n return prepare_templating_benchmark(\"django-components\", \"sm\", \"subsequent\", context_mode)",
|
||||
"min_run_count": 2,
|
||||
"name": "isolated vs django modes.timeraw_render_sm_subsequent",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "render - small - second render",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "7444bc9516dd087e3f420349345eae991ad6941bbd22fce45265b18034b7cf77",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"isolated vs django modes.timeraw_startup_lg": {
|
||||
"code": "class IsolatedVsDjangoContextModesTests:\n @benchmark(\n pretty_name=\"startup - large\",\n group_name=DJC_ISOLATED_VS_NON_GROUP,\n number=1,\n rounds=5,\n params={\n \"context_mode\": [\"isolated\", \"django\"],\n },\n )\n def timeraw_startup_lg(self, context_mode: DjcContextMode):\n return prepare_templating_benchmark(\"django-components\", \"lg\", \"startup\", context_mode)",
|
||||
"min_run_count": 2,
|
||||
"name": "isolated vs django modes.timeraw_startup_lg",
|
||||
"number": 1,
|
||||
"param_names": [
|
||||
"context_mode"
|
||||
],
|
||||
"params": [
|
||||
[
|
||||
"'isolated'",
|
||||
"'django'"
|
||||
]
|
||||
],
|
||||
"pretty_name": "startup - large",
|
||||
"repeat": 0,
|
||||
"rounds": 5,
|
||||
"sample_time": 0.01,
|
||||
"type": "time",
|
||||
"unit": "seconds",
|
||||
"version": "eabe311ebee4a15c5816617be12f00ec30376f7506bd668219e1c50bc897c134",
|
||||
"warmup_time": -1
|
||||
},
|
||||
"version": 2
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
.asv/results/ci-linux/machine.json
Normal file
4
.asv/results/ci-linux/machine.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"machine": "ci-linux",
|
||||
"version": 1
|
||||
}
|
32
.devcontainer/devcontainer.json
Normal file
32
.devcontainer/devcontainer.json
Normal file
|
@ -0,0 +1,32 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
|
||||
{
|
||||
// Uncomment to run Python 3.13 or other specific version
|
||||
// "image": "mcr.microsoft.com/devcontainers/python:3.13-bullseye",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
// Configure properties specific to VS Code.
|
||||
"vscode": {
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"python.defaultInterpreterPath": "/usr/local/bin/python",
|
||||
"python.linting.enabled": true
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-python.python",
|
||||
"ms-python.vscode-pylance",
|
||||
"ms-python.vscode-python-envs",
|
||||
"jurooravec.python-inline-source-2"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
//"postCreateCommand": ""
|
||||
}
|
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
|
@ -9,3 +9,9 @@ updates:
|
|||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: github-actions
|
||||
# This actually targets ./.github/workflows/
|
||||
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#directories-or-directory--
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: monthly
|
||||
|
|
163
.github/workflows/docs.yml
vendored
163
.github/workflows/docs.yml
vendored
|
@ -9,11 +9,6 @@ on:
|
|||
- '[0-9]+.[0-9]+.[0-9]+'
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
@ -25,25 +20,139 @@ jobs:
|
|||
id-token: write # to verify the deployment originates from an appropriate source
|
||||
runs-on: ubuntu-latest
|
||||
# Only run in original repo (not in forks)
|
||||
if: github.repository == 'EmilStenstrom/django-components'
|
||||
if: github.repository == 'django-components/django-components'
|
||||
steps:
|
||||
|
||||
##############################
|
||||
# SETUP
|
||||
##############################
|
||||
|
||||
# Authenticate with git with the Github App that has permission
|
||||
# to push to master, in order to push benchmark results.
|
||||
# See https://stackoverflow.com/a/79142962/9788634
|
||||
- uses: actions/create-github-app-token@v2
|
||||
id: app-token
|
||||
with:
|
||||
app-id: ${{ vars.RELEASE_BOT_APP_ID }}
|
||||
private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Configure git account
|
||||
run: |
|
||||
git config user.name components-release-bot
|
||||
git config user.email "components-release-bot@users.noreply.github.com"
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.13"
|
||||
cache: 'pip'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip wheel
|
||||
# NOTE: pin virtualenv to <20.31 until asv fixes it.
|
||||
# See https://github.com/airspeed-velocity/asv/issues/1484
|
||||
python -m pip install -q hatch pre-commit asv virtualenv==20.30
|
||||
hatch --version
|
||||
|
||||
###########################################
|
||||
# RECORD BENCHMARK - ONLY ON PUSH TO MASTER
|
||||
###########################################
|
||||
|
||||
- name: Run benchmarks for tag
|
||||
if: github.ref_type == 'tag' && github.event_name == 'push'
|
||||
env:
|
||||
# See https://github.com/github/docs/issues/21930
|
||||
# And https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
# Get the master branch so we can run benchmarks on it
|
||||
git remote add upstream https://github.com/${{ github.repository }}.git
|
||||
git fetch origin master:master
|
||||
git checkout master
|
||||
|
||||
# Get tag name
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
echo "TAG: $TAG"
|
||||
|
||||
# TODO: REMOVE ONCE FIXED UPSTREAM
|
||||
# Fix for https://github.com/airspeed-velocity/asv_runner/issues/45
|
||||
# Prepare virtual environment
|
||||
# Currently, we have to monkeypatch the `timeit` function in the `timeraw` benchmark.
|
||||
# The problem is that `asv` passes the code to execute via command line, and when the
|
||||
# code is too big, it fails with `OSError: [Errno 7] Argument list too long`.
|
||||
# So we have to tweak it to pass the code via STDIN, which doesn't have this limitation.
|
||||
#
|
||||
# 1. First create the virtual environment, so that asv generates the directories where
|
||||
# the monkeypatch can be applied.
|
||||
echo "Creating virtual environment..."
|
||||
asv setup -v || true
|
||||
echo "Virtual environment created."
|
||||
# 2. Now let's apply the monkeypatch by appending it to the `timeraw.py` files.
|
||||
# First find all `timeraw.py` files
|
||||
echo "Applying monkeypatch..."
|
||||
find .asv/env -type f -path "*/site-packages/asv_runner/benchmarks/timeraw.py" | while read -r file; do
|
||||
# Add a newline and then append the monkeypatch contents
|
||||
echo "" >> "$file"
|
||||
cat "benchmarks/monkeypatch_asv_ci.txt" >> "$file"
|
||||
done
|
||||
echo "Monkeypatch applied."
|
||||
# END OF MONKEYPATCH
|
||||
|
||||
# Prepare the profile under which the benchmarks will be saved.
|
||||
# We assume that the CI machine has a name that is unique and stable.
|
||||
# See https://github.com/airspeed-velocity/asv/issues/796#issuecomment-1188431794
|
||||
echo "Preparing benchmarks profile..."
|
||||
asv machine --yes --machine ci-linux
|
||||
echo "Benchmarks profile DONE."
|
||||
|
||||
# Run benchmarks for the current tag
|
||||
# - `^` means that we mean the COMMIT of the tag's branch, not the BRANCH itself.
|
||||
# Without it, we would run benchmarks for the whole branch history.
|
||||
# With it, we run benchmarks FROM the tag's commit (incl) TO ...
|
||||
# - `!` means that we want to select range spanning a single commit.
|
||||
# Without it, we would run benchmarks for all commits FROM the tag's commit
|
||||
# TO the start of the branch history.
|
||||
# With it, we run benchmarks ONLY FOR the tag's commit.
|
||||
echo "Running benchmarks for tag ${TAG}..."
|
||||
asv run master^! -v
|
||||
echo "Benchmarks for tag ${TAG} DONE."
|
||||
|
||||
# Generate benchmarks site
|
||||
# This should save it in `docs/benchmarks/`, so we can then use it when
|
||||
# building docs site with `mkdocs`.
|
||||
echo "Generating benchmarks site..."
|
||||
asv publish
|
||||
echo "Benchmarks site DONE."
|
||||
|
||||
# Commit benchmark results
|
||||
echo "Staging and committing benchmark results..."
|
||||
git add .asv/results/
|
||||
git add docs/benchmarks/
|
||||
git commit -m "Add benchmark results for ${TAG}"
|
||||
echo "Benchmark results committed."
|
||||
|
||||
# Push to the new branch
|
||||
echo "Pushing benchmark results..."
|
||||
git push origin master
|
||||
echo "Benchmark results pushed to master."
|
||||
|
||||
###########################################
|
||||
# BUILD & RELEASE DOCS
|
||||
###########################################
|
||||
|
||||
# Change git authentication to Github Actions, so the rest of the
|
||||
# workflow will have lower privileges.
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install Hatch
|
||||
run: |
|
||||
python -m pip install --upgrade pip wheel
|
||||
python -m pip install -q hatch pre-commit
|
||||
hatch --version
|
||||
|
||||
- name: Create Virtual Environment
|
||||
run: hatch env create docs
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
|
@ -64,17 +173,23 @@ jobs:
|
|||
- name: Build & deploy "dev" docs for a new commit to master
|
||||
if: github.event_name == 'push' && github.ref_type != 'tag'
|
||||
run: |
|
||||
# Fetch and checkout gh-pages to ensure we have the latest version
|
||||
git fetch origin gh-pages
|
||||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
git checkout master
|
||||
|
||||
export SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||
hatch run docs:mike deploy --push --update-aliases --title "dev (${SHORT_SHA})" dev
|
||||
|
||||
- name: Build & deploy docs for a new tag
|
||||
if: github.ref_type == 'tag' && github.event_name == 'push'
|
||||
run: |
|
||||
hatch run docs:mike deploy --push --update-aliases ${{ github.ref_name }} latest
|
||||
hatch run docs:mike set-default latest --push
|
||||
# Fetch and checkout gh-pages to ensure we have the latest version
|
||||
git fetch origin gh-pages
|
||||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
git checkout master
|
||||
|
||||
- name: Build & deploy docs for a new release
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
hatch run docs:mike deploy --push --update-aliases ${{ github.ref_name }} latest
|
||||
hatch run docs:mike set-default latest --push
|
||||
|
|
99
.github/workflows/pr-benchmark-comment.yml
vendored
Normal file
99
.github/workflows/pr-benchmark-comment.yml
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
# Run benchmark report on pull requests to master.
|
||||
# The report is added to the PR as a comment.
|
||||
#
|
||||
# NOTE: When making a PR from a fork, the worker doesn't have sufficient
|
||||
# access to make comments on the target repo's PR. And so, this workflow
|
||||
# is split to two parts:
|
||||
#
|
||||
# 1. Benchmarking and saving results as artifacts
|
||||
# 2. Downloading the results and commenting on the PR
|
||||
#
|
||||
# See https://stackoverflow.com/a/71683208/9788634
|
||||
|
||||
name: PR benchmark comment
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
# NOTE: The name here MUST match the name of the workflow that generates the data
|
||||
workflows: [PR benchmarks generate]
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
download:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
repository-projects: write
|
||||
steps:
|
||||
########## USE FOR DEBUGGING ##########
|
||||
- name: Debug workflow run info
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
console.log('Workflow Run ID:', context.payload.workflow_run.id);
|
||||
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id
|
||||
});
|
||||
console.log('Available artifacts:');
|
||||
console.log(JSON.stringify(artifacts.data, null, 2));
|
||||
console.log(`PRs: ` + JSON.stringify(context.payload.workflow_run.pull_requests));
|
||||
#########################################
|
||||
|
||||
# NOTE: The next two steps (download and unzip) are equivalent to using `actions/download-artifact@v4`
|
||||
# However, `download-artifact` was not picking up the artifact, while the REST client does.
|
||||
- name: Download benchmark results
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
|
||||
// Find the artifact that was generated by the "pr-benchmark-generate" workflow
|
||||
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
// Explicitly search the workflow run that generated the the results
|
||||
// (AKA the "pr-benchmark-generate" workflow).
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "benchmark_results"
|
||||
})[0];
|
||||
|
||||
// Download the artifact
|
||||
const download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
fs.writeFileSync(
|
||||
`${process.env.GITHUB_WORKSPACE}/benchmark_results.zip`,
|
||||
Buffer.from(download.data),
|
||||
);
|
||||
|
||||
- name: Unzip artifact
|
||||
run: unzip benchmark_results.zip
|
||||
|
||||
- name: Comment on PR
|
||||
# See https://github.com/actions/github-script
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const results = fs.readFileSync('./benchmark_results.md', 'utf8');
|
||||
const issue_number = Number.parseInt(fs.readFileSync('./pr_number.txt', 'utf8'));
|
||||
const body = `## Performance Benchmark Results\n\nComparing PR changes against master branch:\n\n${results}`;
|
||||
|
||||
// See https://octokit.github.io/rest.js/v21/#issues-create-comment
|
||||
await github.rest.issues.createComment({
|
||||
body: body,
|
||||
// See https://github.com/actions/toolkit/blob/662b9d91f584bf29efbc41b86723e0e376010e41/packages/github/src/context.ts#L66
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
});
|
112
.github/workflows/pr-benchmark-generate.yml
vendored
Normal file
112
.github/workflows/pr-benchmark-generate.yml
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
# Run benchmark report on pull requests to master.
|
||||
# The report is added to the PR as a comment.
|
||||
#
|
||||
# NOTE: When making a PR from a fork, the worker doesn't have sufficient
|
||||
# access to make comments on the target repo's PR. And so, this workflow
|
||||
# is split to two parts:
|
||||
#
|
||||
# 1. Benchmarking and saving results as artifacts
|
||||
# 2. Downloading the results and commenting on the PR
|
||||
#
|
||||
# See https://stackoverflow.com/a/71683208/9788634
|
||||
|
||||
name: PR benchmarks generate
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
benchmark:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Need full history for ASV
|
||||
|
||||
- name: Fetch base branch
|
||||
run: |
|
||||
git remote add upstream https://github.com/${{ github.repository }}.git
|
||||
git fetch upstream master
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.13'
|
||||
cache: 'pip'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
# NOTE: pin virtualenv to <20.31 until asv fixes it.
|
||||
# See https://github.com/airspeed-velocity/asv/issues/1484
|
||||
pip install asv virtualenv==20.30
|
||||
|
||||
- name: Run benchmarks
|
||||
run: |
|
||||
# TODO: REMOVE ONCE FIXED UPSTREAM
|
||||
# Fix for https://github.com/airspeed-velocity/asv_runner/issues/45
|
||||
# Prepare virtual environment
|
||||
# Currently, we have to monkeypatch the `timeit` function in the `timeraw` benchmark.
|
||||
# The problem is that `asv` passes the code to execute via command line, and when the
|
||||
# code is too big, it fails with `OSError: [Errno 7] Argument list too long`.
|
||||
# So we have to tweak it to pass the code via STDIN, which doesn't have this limitation.
|
||||
#
|
||||
# 1. First create the virtual environment, so that asv generates the directories where
|
||||
# the monkeypatch can be applied.
|
||||
echo "Creating virtual environment..."
|
||||
asv setup -v || true
|
||||
echo "Virtual environment created."
|
||||
# 2. Now let's apply the monkeypatch by appending it to the `timeraw.py` files.
|
||||
# First find all `timeraw.py` files
|
||||
echo "Applying monkeypatch..."
|
||||
find .asv/env -type f -path "*/site-packages/asv_runner/benchmarks/timeraw.py" | while read -r file; do
|
||||
# Add a newline and then append the monkeypatch contents
|
||||
echo "" >> "$file"
|
||||
cat "benchmarks/monkeypatch_asv_ci.txt" >> "$file"
|
||||
done
|
||||
echo "Monkeypatch applied."
|
||||
# END OF MONKEYPATCH
|
||||
|
||||
# Prepare the profile under which the benchmarks will be saved.
|
||||
# We assume that the CI machine has a name that is unique and stable.
|
||||
# See https://github.com/airspeed-velocity/asv/issues/796#issuecomment-1188431794
|
||||
echo "Preparing benchmarks profile..."
|
||||
MACHINE="ci_benchmark_${{ github.event.pull_request.number }}"
|
||||
asv machine --yes -v --machine ${MACHINE}
|
||||
echo "Benchmarks profile DONE."
|
||||
|
||||
# Generate benchmark data
|
||||
# - `^` means that we mean the COMMIT of the branch, not the BRANCH itself.
|
||||
# Without it, we would run benchmarks for the whole branch history.
|
||||
# With it, we run benchmarks FROM the latest commit (incl) TO ...
|
||||
# - `!` means that we want to select range spanning a single commit.
|
||||
# Without it, we would run benchmarks for all commits FROM the latest commit
|
||||
# TO the start of the branch history.
|
||||
# With it, we run benchmarks ONLY FOR the latest commit.
|
||||
echo "Running benchmarks for upstream/master..."
|
||||
DJC_BENCHMARK_QUICK=1 asv run upstream/master^! -v --machine ${MACHINE}
|
||||
echo "Benchmarks for upstream/master DONE."
|
||||
echo "Running benchmarks for HEAD..."
|
||||
DJC_BENCHMARK_QUICK=1 asv run HEAD^! -v --machine ${MACHINE}
|
||||
echo "Benchmarks for HEAD DONE."
|
||||
|
||||
echo "Creating pr directory..."
|
||||
mkdir -p pr
|
||||
# Save the PR number to a file, so that it can be used by the next step.
|
||||
echo "${{ github.event.pull_request.number }}" > ./pr/pr_number.txt
|
||||
|
||||
# Compare against master
|
||||
# NOTE: The command is run twice, once so we can see the debug output, and once to save the results.
|
||||
echo "Comparing benchmarks... (debug)"
|
||||
asv compare upstream/master HEAD --factor 1.1 --split --machine ${MACHINE} --verbose
|
||||
echo "Comparing benchmarks... (saving results)"
|
||||
asv compare upstream/master HEAD --factor 1.1 --split --machine ${MACHINE} > ./pr/benchmark_results.md
|
||||
echo "Benchmarks comparison DONE."
|
||||
|
||||
- name: Save benchmark results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: benchmark_results
|
||||
path: pr/
|
8
.github/workflows/publish-to-pypi.yml
vendored
8
.github/workflows/publish-to-pypi.yml
vendored
|
@ -12,15 +12,15 @@ on:
|
|||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'EmilStenstrom/django-components'
|
||||
if: github.repository == 'django-components/django-components'
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.9'
|
||||
python-version: '3.13'
|
||||
|
||||
- name: Install pypa/build
|
||||
run: >-
|
||||
|
|
46
.github/workflows/tests.yml
vendored
46
.github/workflows/tests.yml
vendored
|
@ -14,9 +14,19 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
|
||||
os: [ubuntu-20.04, windows-latest]
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
|
||||
steps:
|
||||
# Configure git to handle long paths
|
||||
# See https://stackoverflow.com/questions/22575662/filename-too-long-in-git-for-windows
|
||||
#
|
||||
# Long paths that are over the limit are because of the benchmarking data
|
||||
# created by asv, as these may look like this:
|
||||
# docs/benchmarks/graphs/arch-x86_64/branch-master/cpu-AMD EPYC 7763 64-Core Processor/django-5.1/djc-core-html-parser/machine-fv-az1693-854/num_cpu-4/os-Linux 6.8.0-1021-azure/python-3.13/ram-16373792/isolated vs django modes.timeraw_render_lg_subsequent.json
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config --global core.longpaths true
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
|
@ -35,7 +45,7 @@ jobs:
|
|||
|
||||
# Verify that docs build
|
||||
test_docs:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.13']
|
||||
|
@ -57,3 +67,35 @@ jobs:
|
|||
python -m pip install -e .
|
||||
- name: Build documentation
|
||||
run: mkdocs build --verbose
|
||||
|
||||
# Verify that the sample project works
|
||||
test_sampleproject:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.13']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd sampleproject
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install -r requirements.txt
|
||||
# Install django-components locally
|
||||
python -m pip install -e ..
|
||||
- name: Check Django project
|
||||
run: |
|
||||
cd sampleproject
|
||||
python manage.py check
|
||||
python manage.py migrate --noinput
|
||||
# Start the server, make request, and exit with error if it fails
|
||||
python manage.py runserver & sleep 5
|
||||
curl http://127.0.0.1:8000/ || exit 1
|
||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
|||
# Project-specific files
|
||||
sampleproject/staticfiles/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
@ -43,6 +46,7 @@ htmlcov/
|
|||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
@ -76,7 +80,11 @@ poetry.lock
|
|||
site
|
||||
.direnv/
|
||||
.envrc
|
||||
.mypy_cache/
|
||||
|
||||
# JS, NPM Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Cursor
|
||||
.cursorrules
|
1981
CHANGELOG.md
1981
CHANGELOG.md
File diff suppressed because it is too large
Load diff
564
README.md
564
README.md
|
@ -1,77 +1,565 @@
|
|||
# <img src="https://raw.githubusercontent.com/EmilStenstrom/django-components/master/logo/logo-black-on-white.svg" alt="django-components" style="max-width: 100%; background: white; color: black;">
|
||||
# <img src="https://raw.githubusercontent.com/django-components/django-components/master/logo/logo-black-on-white.svg" alt="django-components" style="max-width: 100%; background: white; color: black;">
|
||||
|
||||
[](https://pypi.org/project/django-components/) [](https://pypi.org/project/django-components/) [](https://github.com/EmilStenstrom/django-components/blob/master/LICENSE/) [](https://pypistats.org/packages/django-components) [](https://github.com/EmilStenstrom/django-components/actions/workflows/tests.yml)
|
||||
[](https://pypi.org/project/django-components/) [](https://pypi.org/project/django-components/) [](https://github.com/django-components/django-components/blob/master/LICENSE/) [](https://pypistats.org/packages/django-components) [](https://github.com/django-components/django-components/actions/workflows/tests.yml) [](https://django-components.github.io/django-components/latest/benchmarks/)
|
||||
|
||||
[**Docs (Work in progress)**](https://EmilStenstrom.github.io/django-components/latest/)
|
||||
### <table><td>[Read the full documentation](https://django-components.github.io/django-components/latest/)</td></table>
|
||||
|
||||
Django-components is a package that introduces component-based architecture to Django's server-side rendering. It aims to combine Django's templating system with the modularity seen in modern frontend frameworks.
|
||||
`django-components` is a modular and extensible UI framework for Django.
|
||||
|
||||
## Features
|
||||
It combines Django's templating system with the modularity seen
|
||||
in modern frontend frameworks like Vue or React.
|
||||
|
||||
1. 🧩 **Reusability:** Allows creation of self-contained, reusable UI elements.
|
||||
2. 📦 **Encapsulation:** Each component can include its own HTML, CSS, and JavaScript.
|
||||
3. 🚀 **Server-side rendering:** Components render on the server, improving initial load times and SEO.
|
||||
4. 🐍 **Django integration:** Works within the Django ecosystem, using familiar concepts like template tags.
|
||||
5. ⚡ **Asynchronous loading:** Components can render independently opening up for integration with JS frameworks like HTMX or AlpineJS.
|
||||
|
||||
Potential benefits:
|
||||
|
||||
- 🔄 Reduced code duplication
|
||||
- 🛠️ Improved maintainability through modular design
|
||||
- 🧠 Easier management of complex UIs
|
||||
- 🤝 Enhanced collaboration between frontend and backend developers
|
||||
|
||||
Django-components can be particularly useful for larger Django projects that require a more structured approach to UI development, without necessitating a shift to a separate frontend framework.
|
||||
With `django-components` you can support Django projects small and large without leaving the Django ecosystem.
|
||||
|
||||
## Quickstart
|
||||
|
||||
django-components lets you create reusable blocks of code needed to generate the front end code you need for a modern app.
|
||||
A component in django-components can be as simple as a Django template and Python code to declare the component:
|
||||
|
||||
Define a component in `components/calendar/calendar.py` like this:
|
||||
```python
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_name = "template.html"
|
||||
|
||||
def get_context_data(self, date):
|
||||
return {"date": date}
|
||||
```django
|
||||
{# components/calendar/calendar.html #}
|
||||
<div class="calendar">
|
||||
Today's date is <span>{{ date }}</span>
|
||||
</div>
|
||||
```
|
||||
|
||||
With this `template.html` file:
|
||||
```py
|
||||
# components/calendar/calendar.py
|
||||
from django_components import Component, register
|
||||
|
||||
```htmldjango
|
||||
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_file = "calendar.html"
|
||||
```
|
||||
|
||||
Or a combination of Django template, Python, CSS, and Javascript:
|
||||
|
||||
```django
|
||||
{# components/calendar/calendar.html #}
|
||||
<div class="calendar">
|
||||
Today's date is <span>{{ date }}</span>
|
||||
</div>
|
||||
```
|
||||
|
||||
```css
|
||||
/* components/calendar/calendar.css */
|
||||
.calendar {
|
||||
width: 200px;
|
||||
background: pink;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
/* components/calendar/calendar.js */
|
||||
document.querySelector(".calendar").onclick = () => {
|
||||
alert("Clicked calendar!");
|
||||
};
|
||||
```
|
||||
|
||||
```py
|
||||
# components/calendar/calendar.py
|
||||
from django_components import Component, register
|
||||
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_file = "calendar.html"
|
||||
js_file = "calendar.js"
|
||||
css_file = "calendar.css"
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"date": kwargs["date"]}
|
||||
```
|
||||
|
||||
Use the component like this:
|
||||
|
||||
```htmldjango
|
||||
```django
|
||||
{% component "calendar" date="2024-11-06" %}{% endcomponent %}
|
||||
```
|
||||
|
||||
And this is what gets rendered:
|
||||
|
||||
```html
|
||||
<div class="calendar-component">Today's date is <span>2024-11-06</span></div>
|
||||
<div class="calendar-component">
|
||||
Today's date is <span>2024-11-06</span>
|
||||
</div>
|
||||
```
|
||||
|
||||
Read on to learn about all the exciting details and configuration possibilities!
|
||||
|
||||
(If you instead prefer to jump right into the code, [check out the example project](https://github.com/EmilStenstrom/django-components/tree/master/sampleproject))
|
||||
(If you instead prefer to jump right into the code, [check out the example project](https://github.com/django-components/django-components/tree/master/sampleproject))
|
||||
|
||||
## Features
|
||||
|
||||
### Modern and modular UI
|
||||
|
||||
- Create self-contained, reusable UI elements.
|
||||
- Each component can include its own HTML, CSS, and JS, or additional third-party JS and CSS.
|
||||
- HTML, CSS, and JS can be defined on the component class, or loaded from files.
|
||||
|
||||
```python
|
||||
from django_components import Component
|
||||
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template = """
|
||||
<div class="calendar">
|
||||
Today's date is
|
||||
<span>{{ date }}</span>
|
||||
</div>
|
||||
"""
|
||||
|
||||
css = """
|
||||
.calendar {
|
||||
width: 200px;
|
||||
background: pink;
|
||||
}
|
||||
"""
|
||||
|
||||
js = """
|
||||
document.querySelector(".calendar")
|
||||
.addEventListener("click", () => {
|
||||
alert("Clicked calendar!");
|
||||
});
|
||||
"""
|
||||
|
||||
# Additional JS and CSS
|
||||
class Media:
|
||||
js = ["https://cdn.jsdelivr.net/npm/htmx.org@2/dist/htmx.min.js"]
|
||||
css = ["bootstrap/dist/css/bootstrap.min.css"]
|
||||
|
||||
# Variables available in the template
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {
|
||||
"date": kwargs["date"]
|
||||
}
|
||||
```
|
||||
|
||||
### Composition with slots
|
||||
|
||||
- Render components inside templates with
|
||||
[`{% component %}`](https://django-components.github.io/django-components/latest/reference/template_tags#component) tag.
|
||||
- Compose them with [`{% slot %}`](https://django-components.github.io/django-components/latest/reference/template_tags#slot)
|
||||
and [`{% fill %}`](https://django-components.github.io/django-components/latest/reference/template_tags#fill) tags.
|
||||
- Vue-like slot system, including [scoped slots](https://django-components.github.io/django-components/latest/concepts/fundamentals/slots/#slot-data).
|
||||
|
||||
```django
|
||||
{% component "Layout"
|
||||
bookmarks=bookmarks
|
||||
breadcrumbs=breadcrumbs
|
||||
%}
|
||||
{% fill "header" %}
|
||||
<div class="flex justify-between gap-x-12">
|
||||
<div class="prose">
|
||||
<h3>{{ project.name }}</h3>
|
||||
</div>
|
||||
<div class="font-semibold text-gray-500">
|
||||
{{ project.start_date }} - {{ project.end_date }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfill %}
|
||||
|
||||
{# Access data passed to `{% slot %}` with `data` #}
|
||||
{% fill "tabs" data="tabs_data" %}
|
||||
{% component "TabItem" header="Project Info" %}
|
||||
{% component "ProjectInfo"
|
||||
project=project
|
||||
project_tags=project_tags
|
||||
attrs:class="py-5"
|
||||
attrs:width=tabs_data.width
|
||||
/ %}
|
||||
{% endcomponent %}
|
||||
{% endfill %}
|
||||
{% endcomponent %}
|
||||
```
|
||||
|
||||
### Extended template tags
|
||||
|
||||
`django-components` is designed for flexibility, making working with templates a breeze.
|
||||
|
||||
It extends Django's template tags syntax with:
|
||||
|
||||
<!-- TODO - Document literal lists and dictionaries -->
|
||||
- Literal lists and dictionaries in the template
|
||||
- [Self-closing tags](https://django-components.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax#self-closing-tags) `{% mytag / %}`
|
||||
- [Multi-line template tags](https://django-components.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax#multiline-tags)
|
||||
- [Spread operator](https://django-components.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax#spread-operator) `...` to dynamically pass args or kwargs into the template tag
|
||||
- [Template tags inside literal strings](https://django-components.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax#template-tags-inside-literal-strings) like `"{{ first_name }} {{ last_name }}"`
|
||||
- [Pass dictonaries by their key-value pairs](https://django-components.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax#pass-dictonary-by-its-key-value-pairs) `attr:key=val`
|
||||
|
||||
```django
|
||||
{% component "table"
|
||||
...default_attrs
|
||||
title="Friend list for {{ user.name }}"
|
||||
headers=["Name", "Age", "Email"]
|
||||
data=[
|
||||
{
|
||||
"name": "John"|upper,
|
||||
"age": 30|add:1,
|
||||
"email": "john@example.com",
|
||||
"hobbies": ["reading"],
|
||||
},
|
||||
{
|
||||
"name": "Jane"|upper,
|
||||
"age": 25|add:1,
|
||||
"email": "jane@example.com",
|
||||
"hobbies": ["reading", "coding"],
|
||||
},
|
||||
],
|
||||
attrs:class="py-4 ma-2 border-2 border-gray-300 rounded-md"
|
||||
/ %}
|
||||
```
|
||||
|
||||
You too can define template tags with these features by using
|
||||
[`@template_tag()`](https://django-components.github.io/django-components/latest/reference/api/#django_components.template_tag)
|
||||
or [`BaseNode`](https://django-components.github.io/django-components/latest/reference/api/#django_components.BaseNode).
|
||||
|
||||
Read more on [Custom template tags](https://django-components.github.io/django-components/latest/concepts/advanced/template_tags/).
|
||||
|
||||
### Full programmatic access
|
||||
|
||||
When you render a component, you can access everything about the component:
|
||||
|
||||
- Component input: [args, kwargs, slots and context](https://django-components.github.io/django-components/latest/concepts/fundamentals/render_api/#component-inputs)
|
||||
- Component's template, CSS and JS
|
||||
- Django's [context processors](https://django-components.github.io/django-components/latest/concepts/fundamentals/render_api/#request-and-context-processors)
|
||||
- Unique [render ID](https://django-components.github.io/django-components/latest/concepts/fundamentals/render_api/#component-id)
|
||||
|
||||
```python
|
||||
class Table(Component):
|
||||
js_file = "table.js"
|
||||
css_file = "table.css"
|
||||
|
||||
template = """
|
||||
<div class="table">
|
||||
<span>{{ variable }}</span>
|
||||
</div>
|
||||
"""
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
# Access component's ID
|
||||
assert self.id == "djc1A2b3c"
|
||||
|
||||
# Access component's inputs and slots
|
||||
assert self.args == [123, "str"]
|
||||
assert self.kwargs == {"variable": "test", "another": 1}
|
||||
footer_slot = self.slots["footer"]
|
||||
some_var = self.context["some_var"]
|
||||
|
||||
# Access the request object and Django's context processors, if available
|
||||
assert self.request.GET == {"query": "something"}
|
||||
assert self.context_processors_data['user'].username == "admin"
|
||||
|
||||
return {
|
||||
"variable": kwargs["variable"],
|
||||
}
|
||||
|
||||
# Access component's HTML / JS / CSS
|
||||
Table.template
|
||||
Table.js
|
||||
Table.css
|
||||
|
||||
# Render the component
|
||||
rendered = Table.render(
|
||||
kwargs={"variable": "test", "another": 1},
|
||||
args=(123, "str"),
|
||||
slots={"footer": "MY_FOOTER"},
|
||||
)
|
||||
```
|
||||
|
||||
### Granular HTML attributes
|
||||
|
||||
Use the [`{% html_attrs %}`](https://django-components.github.io/django-components/latest/concepts/fundamentals/html_attributes/) template tag to render HTML attributes.
|
||||
|
||||
It supports:
|
||||
|
||||
- Defining attributes as whole dictionaries or keyword arguments
|
||||
- Merging attributes from multiple sources
|
||||
- Boolean attributes
|
||||
- Appending attributes
|
||||
- Removing attributes
|
||||
- Defining default attributes
|
||||
|
||||
```django
|
||||
<div
|
||||
{% html_attrs
|
||||
attrs
|
||||
defaults:class="default-class"
|
||||
class="extra-class"
|
||||
%}
|
||||
>
|
||||
```
|
||||
|
||||
[`{% html_attrs %}`](https://django-components.github.io/django-components/latest/concepts/fundamentals/html_attributes/) offers a Vue-like granular control for
|
||||
[`class`](https://django-components.github.io/django-components/latest/concepts/fundamentals/html_attributes/#merging-class-attributes)
|
||||
and [`style`](https://django-components.github.io/django-components/latest/concepts/fundamentals/html_attributes/#merging-style-attributes)
|
||||
HTML attributes,
|
||||
where you can use a dictionary to manage each class name or style property separately.
|
||||
|
||||
```django
|
||||
{% html_attrs
|
||||
class="foo bar"
|
||||
class={
|
||||
"baz": True,
|
||||
"foo": False,
|
||||
}
|
||||
class="extra"
|
||||
%}
|
||||
```
|
||||
|
||||
```django
|
||||
{% html_attrs
|
||||
style="text-align: center; background-color: blue;"
|
||||
style={
|
||||
"background-color": "green",
|
||||
"color": None,
|
||||
"width": False,
|
||||
}
|
||||
style="position: absolute; height: 12px;"
|
||||
%}
|
||||
```
|
||||
|
||||
Read more about [HTML attributes](https://django-components.github.io/django-components/latest/concepts/fundamentals/html_attributes/).
|
||||
|
||||
### HTML fragment support
|
||||
|
||||
`django-components` makes integration with HTMX, AlpineJS or jQuery easy by allowing components to be rendered as [HTML fragments](https://django-components.github.io/django-components/latest/concepts/advanced/html_fragments/):
|
||||
|
||||
- Components's JS and CSS files are loaded automatically when the fragment is inserted into the DOM.
|
||||
|
||||
- Components can be [exposed as Django Views](https://django-components.github.io/django-components/latest/concepts/fundamentals/component_views_urls/) with `get()`, `post()`, `put()`, `patch()`, `delete()` methods
|
||||
|
||||
- Automatically create an endpoint for a component with [`Component.View.public`](https://django-components.github.io/django-components/latest/concepts/fundamentals/component_views_urls/#register-urls-automatically)
|
||||
|
||||
```py
|
||||
# components/calendar/calendar.py
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_file = "calendar.html"
|
||||
|
||||
class View:
|
||||
# Register Component with `urlpatterns`
|
||||
public = True
|
||||
|
||||
# Define handlers
|
||||
def get(self, request, *args, **kwargs):
|
||||
page = request.GET.get("page", 1)
|
||||
return self.component.render_to_response(
|
||||
request=request,
|
||||
kwargs={
|
||||
"page": page,
|
||||
},
|
||||
)
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {
|
||||
"page": kwargs["page"],
|
||||
}
|
||||
|
||||
# Get auto-generated URL for the component
|
||||
url = get_component_url(Calendar)
|
||||
|
||||
# Or define explicit URL in urls.py
|
||||
path("calendar/", Calendar.as_view())
|
||||
```
|
||||
|
||||
### Provide / Inject
|
||||
|
||||
`django-components` supports the provide / inject pattern, similarly to React's [Context Providers](https://react.dev/learn/passing-data-deeply-with-context) or Vue's [provide / inject](https://vuejs.org/guide/components/provide-inject):
|
||||
|
||||
- Use the [`{% provide %}`](https://django-components.github.io/django-components/latest/reference/template_tags/#provide) tag to provide data to the component tree
|
||||
- Use the [`Component.inject()`](https://django-components.github.io/django-components/latest/reference/api/#django_components.Component.inject) method to inject data into the component
|
||||
|
||||
Read more about [Provide / Inject](https://django-components.github.io/django-components/latest/concepts/advanced/provide_inject).
|
||||
|
||||
```django
|
||||
<body>
|
||||
{% provide "theme" variant="light" %}
|
||||
{% component "header" / %}
|
||||
{% endprovide %}
|
||||
</body>
|
||||
```
|
||||
|
||||
```djc_py
|
||||
@register("header")
|
||||
class Header(Component):
|
||||
template = "..."
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
theme = self.inject("theme").variant
|
||||
return {
|
||||
"theme": theme,
|
||||
}
|
||||
```
|
||||
|
||||
### Input validation and static type hints
|
||||
|
||||
Avoid needless errors with [type hints and runtime input validation](https://django-components.github.io/django-components/latest/concepts/fundamentals/typing_and_validation/).
|
||||
|
||||
To opt-in to input validation, define types for component's args, kwargs, slots, and more:
|
||||
|
||||
```py
|
||||
from typing import NamedTuple, Optional
|
||||
from django.template import Context
|
||||
from django_components import Component, Slot, SlotInput
|
||||
|
||||
class Button(Component):
|
||||
class Args(NamedTuple):
|
||||
size: int
|
||||
text: str
|
||||
|
||||
class Kwargs(NamedTuple):
|
||||
variable: str
|
||||
another: int
|
||||
maybe_var: Optional[int] = None # May be omitted
|
||||
|
||||
class Slots(NamedTuple):
|
||||
my_slot: Optional[SlotInput] = None
|
||||
another_slot: SlotInput
|
||||
|
||||
def get_template_data(self, args: Args, kwargs: Kwargs, slots: Slots, context: Context):
|
||||
args.size # int
|
||||
kwargs.variable # str
|
||||
slots.my_slot # Slot[MySlotData]
|
||||
```
|
||||
|
||||
To have type hints when calling
|
||||
[`Button.render()`](https://django-components.github.io/django-components/latest/reference/api/#django_components.Component.render) or
|
||||
[`Button.render_to_response()`](https://django-components.github.io/django-components/latest/reference/api/#django_components.Component.render_to_response),
|
||||
wrap the inputs in their respective `Args`, `Kwargs`, and `Slots` classes:
|
||||
|
||||
```py
|
||||
Button.render(
|
||||
# Error: First arg must be `int`, got `float`
|
||||
args=Button.Args(
|
||||
size=1.25,
|
||||
text="abc",
|
||||
),
|
||||
# Error: Key "another" is missing
|
||||
kwargs=Button.Kwargs(
|
||||
variable="text",
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
### Extensions
|
||||
|
||||
Django-components functionality can be extended with [Extensions](https://django-components.github.io/django-components/latest/concepts/advanced/extensions/).
|
||||
Extensions allow for powerful customization and integrations. They can:
|
||||
|
||||
- Tap into lifecycle events, such as when a component is created, deleted, or registered
|
||||
- Add new attributes and methods to the components
|
||||
- Add custom CLI commands
|
||||
- Add custom URLs
|
||||
|
||||
Some of the extensions include:
|
||||
|
||||
- [Component caching](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/cache.py)
|
||||
- [Django View integration](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/view.py)
|
||||
- [Component defaults](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/defaults.py)
|
||||
- [Pydantic integration (input validation)](https://github.com/django-components/djc-ext-pydantic)
|
||||
|
||||
Some of the planned extensions include:
|
||||
|
||||
- AlpineJS integration
|
||||
- Storybook integration
|
||||
- Component-level benchmarking with asv
|
||||
|
||||
### Caching
|
||||
|
||||
- [Components can be cached](https://django-components.github.io/django-components/latest/concepts/advanced/component_caching/) using Django's cache framework.
|
||||
- Caching rules can be configured on a per-component basis.
|
||||
- Components are cached based on their input. Or you can write custom caching logic.
|
||||
|
||||
```py
|
||||
from django_components import Component
|
||||
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
ttl = 60 * 60 * 24 # 1 day
|
||||
|
||||
def hash(self, *args, **kwargs):
|
||||
return hash(f"{json.dumps(args)}:{json.dumps(kwargs)}")
|
||||
```
|
||||
|
||||
### Simple testing
|
||||
|
||||
- Write tests for components with [`@djc_test`](https://django-components.github.io/django-components/latest/concepts/advanced/testing/) decorator.
|
||||
- The decorator manages global state, ensuring that tests don't leak.
|
||||
- If using `pytest`, the decorator allows you to parametrize Django or Components settings.
|
||||
- The decorator also serves as a stand-in for Django's [`@override_settings`](https://docs.djangoproject.com/en/5.2/topics/testing/tools/#django.test.override_settings).
|
||||
|
||||
```python
|
||||
from django_components.testing import djc_test
|
||||
|
||||
from components.my_table import MyTable
|
||||
|
||||
@djc_test
|
||||
def test_my_table():
|
||||
rendered = MyTable.render(
|
||||
kwargs={
|
||||
"title": "My table",
|
||||
},
|
||||
)
|
||||
assert rendered == "<table>My table</table>"
|
||||
```
|
||||
|
||||
### Debugging features
|
||||
|
||||
- **Visual component inspection**: Highlight components and slots directly in your browser.
|
||||
- **Detailed tracing logs to supply AI-agents with context**: The logs include component and slot names and IDs, and their position in the tree.
|
||||
|
||||
<div style="text-align: center;">
|
||||
<img src="https://github.com/django-components/django-components/blob/master/docs/images/debug-highlight-slots.png?raw=true" alt="Component debugging visualization showing slot highlighting" width="500" style="margin: auto;">
|
||||
</div>
|
||||
|
||||
### Sharing components
|
||||
|
||||
- Install and use third-party components from PyPI
|
||||
- Or publish your own "component registry"
|
||||
- Highly customizable - Choose how the components are called in the template (and more):
|
||||
|
||||
```django
|
||||
{% component "calendar" date="2024-11-06" %}
|
||||
{% endcomponent %}
|
||||
|
||||
{% calendar date="2024-11-06" %}
|
||||
{% endcalendar %}
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
[Read the full documentation here](https://django-components.github.io/django-components/latest/).
|
||||
|
||||
... or jump right into the code, [check out the example project](https://github.com/django-components/django-components/tree/master/sampleproject).
|
||||
|
||||
## Performance
|
||||
|
||||
Our aim is to be at least as fast as Django templates.
|
||||
|
||||
As of `0.130`, `django-components` is ~4x slower than Django templates.
|
||||
|
||||
| | Render time|
|
||||
|----------|----------------------|
|
||||
| django | 68.9±0.6ms |
|
||||
| django-components | 259±4ms |
|
||||
|
||||
See the [full performance breakdown](https://django-components.github.io/django-components/latest/benchmarks/) for more information.
|
||||
|
||||
## Release notes
|
||||
|
||||
Read the [Release Notes](https://github.com/EmilStenstrom/django-components/tree/master/CHANGELOG.md)
|
||||
Read the [Release Notes](https://github.com/django-components/django-components/tree/master/CHANGELOG.md)
|
||||
to see the latest features and fixes.
|
||||
|
||||
## Community examples
|
||||
|
||||
One of our goals with `django-components` is to make it easy to share components between projects. If you have a set of components that you think would be useful to others, please open a pull request to add them to the list below.
|
||||
|
||||
- [django-htmx-components](https://github.com/iwanalabs/django-htmx-components): A set of components for use with [htmx](https://htmx.org/). Try out the [live demo](https://dhc.iwanalabs.com/).
|
||||
- [django-htmx-components](https://github.com/iwanalabs/django-htmx-components): A set of components for use with [htmx](https://htmx.org/).
|
||||
|
||||
- [djc-heroicons](https://pypi.org/project/djc-heroicons/): A component that renders icons from [Heroicons.com](https://heroicons.com/).
|
||||
|
||||
## Contributing and development
|
||||
|
||||
Get involved or sponsor this project - [See here](https://emilstenstrom.github.io/django-components/dev/overview/contributing/)
|
||||
Get involved or sponsor this project - [See here](https://django-components.github.io/django-components/dev/overview/contributing/)
|
||||
|
||||
Running django-components locally for development - [See here](https://emilstenstrom.github.io/django-components/dev/overview/development/)
|
||||
Running django-components locally for development - [See here](https://django-components.github.io/django-components/dev/overview/development/)
|
||||
|
|
210
asv.conf.json
Normal file
210
asv.conf.json
Normal file
|
@ -0,0 +1,210 @@
|
|||
{
|
||||
// The version of the config file format. Do not change, unless
|
||||
// you know what you are doing
|
||||
"version": 1,
|
||||
|
||||
// The name of the project being benchmarked
|
||||
"project": "django-components",
|
||||
|
||||
// The project's homepage
|
||||
// "project_url": "https://django-components.github.io/django-components/",
|
||||
"project_url": "/django-components/", // Relative path, since benchmarks are nested under the docs site
|
||||
|
||||
// The URL or local path of the source code repository for the
|
||||
// project being benchmarked
|
||||
"repo": ".",
|
||||
|
||||
// The Python project's subdirectory in your repo. If missing or
|
||||
// the empty string, the project is assumed to be located at the root
|
||||
// of the repository.
|
||||
// "repo_subdir": "",
|
||||
|
||||
// Customizable commands for building the project.
|
||||
// See asv.conf.json documentation.
|
||||
// To build the package using pyproject.toml (PEP518), uncomment the following lines
|
||||
// "build_command": [
|
||||
// "python -m pip install build",
|
||||
// "python -m build",
|
||||
// "python -mpip wheel -w {build_cache_dir} {build_dir}"
|
||||
// ],
|
||||
// To build the package using setuptools and a setup.py file, uncomment the following lines
|
||||
// "build_command": [
|
||||
// "python setup.py build",
|
||||
// "python -mpip wheel -w {build_cache_dir} {build_dir}"
|
||||
// ],
|
||||
|
||||
// Customizable commands for installing and uninstalling the project.
|
||||
// See asv.conf.json documentation.
|
||||
// "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
|
||||
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
|
||||
"install_command": ["in-dir={env_dir} python -mpip install ./project"],
|
||||
|
||||
// List of branches to benchmark. If not provided, defaults to "main"
|
||||
// (for git) or "default" (for mercurial).
|
||||
// "branches": ["main"], // for git
|
||||
// "branches": ["default"], // for mercurial
|
||||
"branches": [
|
||||
"master"
|
||||
],
|
||||
|
||||
// The DVCS being used. If not set, it will be automatically
|
||||
// determined from "repo" by looking at the protocol in the URL
|
||||
// (if remote), or by looking for special directories, such as
|
||||
// ".git" (if local).
|
||||
// "dvcs": "git",
|
||||
|
||||
// The tool to use to create environments. May be "conda",
|
||||
// "virtualenv", "mamba" (above 3.8)
|
||||
// or other value depending on the plugins in use.
|
||||
// If missing or the empty string, the tool will be automatically
|
||||
// determined by looking for tools on the PATH environment
|
||||
// variable.
|
||||
"environment_type": "virtualenv",
|
||||
|
||||
// timeout in seconds for installing any dependencies in environment
|
||||
// defaults to 10 min
|
||||
//"install_timeout": 600,
|
||||
|
||||
// the base URL to show a commit for the project.
|
||||
// "show_commit_url": "http://github.com/owner/project/commit/",
|
||||
|
||||
// The Pythons you'd like to test against. If not provided, defaults
|
||||
// to the current version of Python used to run `asv`.
|
||||
"pythons": [
|
||||
"3.13"
|
||||
],
|
||||
|
||||
// The list of conda channel names to be searched for benchmark
|
||||
// dependency packages in the specified order
|
||||
// "conda_channels": ["conda-forge", "defaults"],
|
||||
|
||||
// A conda environment file that is used for environment creation.
|
||||
// "conda_environment_file": "environment.yml",
|
||||
|
||||
// The matrix of dependencies to test. Each key of the "req"
|
||||
// requirements dictionary is the name of a package (in PyPI) and
|
||||
// the values are version numbers. An empty list or empty string
|
||||
// indicates to just test against the default (latest)
|
||||
// version. null indicates that the package is to not be
|
||||
// installed. If the package to be tested is only available from
|
||||
// PyPi, and the 'environment_type' is conda, then you can preface
|
||||
// the package name by 'pip+', and the package will be installed
|
||||
// via pip (with all the conda available packages installed first,
|
||||
// followed by the pip installed packages).
|
||||
//
|
||||
// The ``@env`` and ``@env_nobuild`` keys contain the matrix of
|
||||
// environment variables to pass to build and benchmark commands.
|
||||
// An environment will be created for every combination of the
|
||||
// cartesian product of the "@env" variables in this matrix.
|
||||
// Variables in "@env_nobuild" will be passed to every environment
|
||||
// during the benchmark phase, but will not trigger creation of
|
||||
// new environments. A value of ``null`` means that the variable
|
||||
// will not be set for the current combination.
|
||||
//
|
||||
// "matrix": {
|
||||
// "req": {
|
||||
// "numpy": ["1.6", "1.7"],
|
||||
// "six": ["", null], // test with and without six installed
|
||||
// "pip+emcee": [""] // emcee is only available for install with pip.
|
||||
// },
|
||||
// "env": {"ENV_VAR_1": ["val1", "val2"]},
|
||||
// "env_nobuild": {"ENV_VAR_2": ["val3", null]},
|
||||
// },
|
||||
"matrix": {
|
||||
"req": {
|
||||
"django": [
|
||||
"5.1"
|
||||
],
|
||||
"djc-core-html-parser": [""] // Empty string means the latest version
|
||||
}
|
||||
},
|
||||
|
||||
// Combinations of libraries/python versions can be excluded/included
|
||||
// from the set to test. Each entry is a dictionary containing additional
|
||||
// key-value pairs to include/exclude.
|
||||
//
|
||||
// An exclude entry excludes entries where all values match. The
|
||||
// values are regexps that should match the whole string.
|
||||
//
|
||||
// An include entry adds an environment. Only the packages listed
|
||||
// are installed. The 'python' key is required. The exclude rules
|
||||
// do not apply to includes.
|
||||
//
|
||||
// In addition to package names, the following keys are available:
|
||||
//
|
||||
// - python
|
||||
// Python version, as in the *pythons* variable above.
|
||||
// - environment_type
|
||||
// Environment type, as above.
|
||||
// - sys_platform
|
||||
// Platform, as in sys.platform. Possible values for the common
|
||||
// cases: 'linux2', 'win32', 'cygwin', 'darwin'.
|
||||
// - req
|
||||
// Required packages
|
||||
// - env
|
||||
// Environment variables
|
||||
// - env_nobuild
|
||||
// Non-build environment variables
|
||||
//
|
||||
// "exclude": [
|
||||
// {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
|
||||
// {"environment_type": "conda", "req": {"six": null}}, // don't run without six on conda
|
||||
// {"env": {"ENV_VAR_1": "val2"}}, // skip val2 for ENV_VAR_1
|
||||
// ],
|
||||
//
|
||||
// "include": [
|
||||
// // additional env for python3.12
|
||||
// {"python": "3.12", "req": {"numpy": "1.26"}, "env_nobuild": {"FOO": "123"}},
|
||||
// // additional env if run on windows+conda
|
||||
// {"platform": "win32", "environment_type": "conda", "python": "3.12", "req": {"libpython": ""}},
|
||||
// ],
|
||||
|
||||
// The directory (relative to the current directory) that benchmarks are
|
||||
// stored in. If not provided, defaults to "benchmarks"
|
||||
"benchmark_dir": "benchmarks",
|
||||
|
||||
// The directory (relative to the current directory) to cache the Python
|
||||
// environments in. If not provided, defaults to "env"
|
||||
"env_dir": ".asv/env",
|
||||
|
||||
// The directory (relative to the current directory) that raw benchmark
|
||||
// results are stored in. If not provided, defaults to "results".
|
||||
"results_dir": ".asv/results",
|
||||
|
||||
// The directory (relative to the current directory) that the html tree
|
||||
// should be written to. If not provided, defaults to "html".
|
||||
// "html_dir": ".asv/html",
|
||||
"html_dir": "docs/benchmarks", // # TODO
|
||||
|
||||
// The number of characters to retain in the commit hashes.
|
||||
// "hash_length": 8,
|
||||
|
||||
// `asv` will cache results of the recent builds in each
|
||||
// environment, making them faster to install next time. This is
|
||||
// the number of builds to keep, per environment.
|
||||
// "build_cache_size": 2,
|
||||
|
||||
// The commits after which the regression search in `asv publish`
|
||||
// should start looking for regressions. Dictionary whose keys are
|
||||
// regexps matching to benchmark names, and values corresponding to
|
||||
// the commit (exclusive) after which to start looking for
|
||||
// regressions. The default is to start from the first commit
|
||||
// with results. If the commit is `null`, regression detection is
|
||||
// skipped for the matching benchmark.
|
||||
//
|
||||
// "regressions_first_commits": {
|
||||
// "some_benchmark": "352cdf", // Consider regressions only after this commit
|
||||
// "another_benchmark": null, // Skip regression detection altogether
|
||||
// },
|
||||
|
||||
// The thresholds for relative change in results, after which `asv
|
||||
// publish` starts reporting regressions. Dictionary of the same
|
||||
// form as in ``regressions_first_commits``, with values
|
||||
// indicating the thresholds. If multiple entries match, the
|
||||
// maximum is taken. If no entry matches, the default is 5%.
|
||||
//
|
||||
// "regressions_thresholds": {
|
||||
// "some_benchmark": 0.01, // Threshold of 1%
|
||||
// "another_benchmark": 0.5, // Threshold of 50%
|
||||
// },
|
||||
}
|
195
benchmarks/README.md
Normal file
195
benchmarks/README.md
Normal file
|
@ -0,0 +1,195 @@
|
|||
# Benchmarks
|
||||
|
||||
## Overview
|
||||
|
||||
[`asv`](https://github.com/airspeed-velocity/) (Airspeed Velocity) is used for benchmarking performance.
|
||||
|
||||
`asv` covers the entire benchmarking workflow. We can:
|
||||
|
||||
1. Define benchmark tests similarly to writing pytest tests (supports both timing and memory benchmarks)
|
||||
2. Run the benchmarks and generate results for individual git commits, tags, or entire branches
|
||||
3. View results as an HTML report (dashboard with charts)
|
||||
4. Compare performance between two commits / tags / branches for CI integration
|
||||
|
||||

|
||||
|
||||
django-components uses `asv` for these use cases:
|
||||
|
||||
- Benchmarking across releases:
|
||||
|
||||
1. When a git tag is created and pushed, this triggers a Github Action workflow (see `docs.yml`).
|
||||
2. The workflow runs the benchmarks with the latest release, and commits the results to the repository.
|
||||
Thus, we can see how performance changes across releases.
|
||||
|
||||
- Displaying performance results on the website:
|
||||
|
||||
1. When a git tag is created and pushed, we also update the documentation website (see `docs.yml`).
|
||||
2. Before we publish the docs website, we generate the HTML report for the benchmark results.
|
||||
3. The generated report is placed in the `docs/benchmarks/` directory, and is thus
|
||||
published with the rest of the docs website and available under [`/benchmarks/`](https://django-components.github.io/django-components/latest/benchmarks).
|
||||
- NOTE: The location where the report is placed is defined in `asv.conf.json`.
|
||||
|
||||
- Compare performance between commits on pull requests:
|
||||
1. When a pull request is made, this triggers a Github Action workflow (see `benchmark.yml`).
|
||||
2. The workflow compares performance between commits.
|
||||
3. The report is added to the PR as a comment made by a bot.
|
||||
|
||||
## Interpreting benchmarks
|
||||
|
||||
The results CANNOT be taken as ABSOLUTE values e.g.:
|
||||
|
||||
"This example took 200ms to render, so my page will also take 200ms to render."
|
||||
|
||||
Each UI may consist of different number of Django templates, template tags, and components, and all these may influence the rendering time differently.
|
||||
|
||||
Instead, the results MUST be understood as RELATIVE values.
|
||||
|
||||
- If a commit is 10% slower than the master branch, that's valid.
|
||||
- If Django components are 10% slower than vanilla Django templates, that's valid.
|
||||
- If "isolated" mode is 10% slower than "django" mode, that's valid.
|
||||
|
||||
## Development
|
||||
|
||||
Let's say we want to generate results for the last 5 commits.
|
||||
|
||||
1. Install `asv`
|
||||
|
||||
```bash
|
||||
pip install asv
|
||||
```
|
||||
|
||||
2. Run benchmarks and generate results
|
||||
|
||||
```bash
|
||||
asv run HEAD --steps 5 -e
|
||||
```
|
||||
|
||||
- `HEAD` means that we want to run benchmarks against the [current branch](https://stackoverflow.com/a/2304106/9788634).
|
||||
- `--steps 5` means that we want to run benchmarks for the last 5 commits.
|
||||
- `-e` to print out any errors.
|
||||
|
||||
The results will be stored in `.asv/results/`, as configured in `asv.conf.json`.
|
||||
|
||||
3. Generate HTML report
|
||||
|
||||
```bash
|
||||
asv publish
|
||||
asv preview
|
||||
```
|
||||
|
||||
- `publish` generates the HTML report and stores it in `docs/benchmarks/`, as configured in `asv.conf.json`.
|
||||
- `preview` starts a local server and opens the report in the browser.
|
||||
|
||||
NOTE: Since the results are stored in `docs/benchmarks/`, you can also view the results
|
||||
with `mkdocs serve` and navigating to `http://localhost:9000/django-components/benchmarks/`.
|
||||
|
||||
NOTE 2: Running `publish` will overwrite the existing contents of `docs/benchmarks/`.
|
||||
|
||||
## Writing benchmarks
|
||||
|
||||
`asv` supports writing different [types of benchmarks](https://asv.readthedocs.io/en/latest/writing_benchmarks.html#benchmark-types). What's relevant for us is:
|
||||
|
||||
- [Raw timing benchmarks](https://asv.readthedocs.io/en/latest/writing_benchmarks.html#raw-timing-benchmarks)
|
||||
- [Peak memory benchmarks](https://asv.readthedocs.io/en/latest/writing_benchmarks.html#peak-memory)
|
||||
|
||||
Notes:
|
||||
|
||||
- The difference between "raw timing" and "timing" tests is that "raw timing" is ran in a separate process.
|
||||
And instead of running the logic within the test function itself, we return a script (string)
|
||||
that will be executed in the separate process.
|
||||
|
||||
- The difference between "peak memory" and "memory" tests is that "memory" calculates the memory
|
||||
of the object returned from the test function. On the other hand, "peak memory" detects the
|
||||
peak memory usage during the execution of the test function (including the setup function).
|
||||
|
||||
You can write the test file anywhere in the `benchmarks/` directory, `asv` will automatically find it.
|
||||
|
||||
Inside the file, write a test function. Depending on the type of the benchmark,
|
||||
prefix the test function name with `timeraw_` or `peakmem_`. See [`benchmarks/benchmark_templating.py`](benchmark_templating.py) for examples.
|
||||
|
||||
### Ensuring that the benchmarked logic is correct
|
||||
|
||||
The approach I (Juro) took with benchmarking the overall template rendering is that
|
||||
I've defined the actual logic in `tests/test_benchmark_*.py` files. So those files
|
||||
are part of the normal pytest testing, and even contain a section with pytest tests.
|
||||
|
||||
This ensures that the benchmarked logic remains functional and error-free.
|
||||
|
||||
However, there's some caveats:
|
||||
|
||||
1. I wasn't able to import files from `tests/`.
|
||||
2. When running benchmarks, we don't want to run the pytest tests.
|
||||
|
||||
To work around that, the approach I used for loading the files from the `tests/` directory is to:
|
||||
|
||||
1. Get the file's source code as a string.
|
||||
2. Cut out unwanted sections (like the pytest tests).
|
||||
3. Append the benchmark-specific code to the file (e.g. to actually render the templates).
|
||||
4. In case of "timeraw" benchmarks, we can simply return the remaining code as a string
|
||||
to be run in a separate process.
|
||||
5. In case of "peakmem" benchmarks, we need to access this modified source code as Python objects.
|
||||
So the code is made available as a "virtual" module, which makes it possible to import Python objects like so:
|
||||
```py
|
||||
from my_virtual_module import run_my_benchmark
|
||||
```
|
||||
|
||||
## Using `asv`
|
||||
|
||||
### Compare latest commit against master
|
||||
|
||||
Note: Before comparing, you must run the benchmarks first to generate the results. The `continuous` command does not generate the results by itself.
|
||||
|
||||
```bash
|
||||
asv continuous master^! HEAD^! --factor 1.1
|
||||
```
|
||||
|
||||
- Factor of `1.1` means that the new commit is allowed to be 10% slower/faster than the master commit.
|
||||
|
||||
- `^` means that we mean the COMMIT of the branch, not the BRANCH itself.
|
||||
|
||||
Without it, we would run benchmarks for the whole branch history.
|
||||
|
||||
With it, we run benchmarks FROM the latest commit (incl) TO ...
|
||||
|
||||
- `!` means that we want to select range spanning a single commit.
|
||||
|
||||
Without it, we would run benchmarks for all commits FROM the latest commit
|
||||
TO the start of the branch history.
|
||||
|
||||
With it, we run benchmarks ONLY FOR the latest commit.
|
||||
|
||||
### More Examples
|
||||
|
||||
Notes:
|
||||
|
||||
- Use `~1` to select the second-latest commit, `~2` for the third-latest, etc..
|
||||
|
||||
Generate benchmarks for the latest commit in `master` branch.
|
||||
|
||||
```bash
|
||||
asv run master^!
|
||||
```
|
||||
|
||||
Generate benchmarks for second-latest commit in `master` branch.
|
||||
|
||||
```bash
|
||||
asv run master~1^!
|
||||
```
|
||||
|
||||
Generate benchmarks for all commits in `master` branch.
|
||||
|
||||
```bash
|
||||
asv run master
|
||||
```
|
||||
|
||||
Generate benchmarks for all commits in `master` branch, but exclude the latest commit.
|
||||
|
||||
```bash
|
||||
asv run master~1
|
||||
```
|
||||
|
||||
Generate benchmarks for the LAST 5 commits in `master` branch, but exclude the latest commit.
|
||||
|
||||
```bash
|
||||
asv run master~1 --steps 5
|
||||
```
|
0
benchmarks/__init__.py
Normal file
0
benchmarks/__init__.py
Normal file
BIN
benchmarks/assets/asv_dashboard.png
Normal file
BIN
benchmarks/assets/asv_dashboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 321 KiB |
446
benchmarks/benchmark_templating.py
Normal file
446
benchmarks/benchmark_templating.py
Normal file
|
@ -0,0 +1,446 @@
|
|||
# Write the benchmarking functions here
|
||||
# See "Writing benchmarks" in the asv docs for more information.
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Literal
|
||||
|
||||
# Fix for for https://github.com/airspeed-velocity/asv_runner/pull/44
|
||||
import benchmarks.monkeypatch_asv # noqa: F401
|
||||
|
||||
from benchmarks.utils import benchmark, create_virtual_module
|
||||
|
||||
|
||||
DJC_VS_DJ_GROUP = "Components vs Django"
|
||||
DJC_ISOLATED_VS_NON_GROUP = "isolated vs django modes"
|
||||
OTHER_GROUP = "Other"
|
||||
|
||||
|
||||
DjcContextMode = Literal["isolated", "django"]
|
||||
TemplatingRenderer = Literal["django", "django-components", "none"]
|
||||
TemplatingTestSize = Literal["lg", "sm"]
|
||||
TemplatingTestType = Literal[
|
||||
"first", # Testing performance of the first time the template is rendered
|
||||
"subsequent", # Testing performance of the subsequent times the template is rendered
|
||||
"startup", # Testing performance of the startup time (e.g. defining classes and templates)
|
||||
]
|
||||
|
||||
|
||||
def _get_templating_filepath(renderer: TemplatingRenderer, size: TemplatingTestSize) -> Path:
|
||||
if renderer == "none":
|
||||
raise ValueError("Cannot get filepath for renderer 'none'")
|
||||
elif renderer not in ["django", "django-components"]:
|
||||
raise ValueError(f"Invalid renderer: {renderer}")
|
||||
|
||||
if size not in ("lg", "sm"):
|
||||
raise ValueError(f"Invalid size: {size}, must be one of ('lg', 'sm')")
|
||||
|
||||
# At this point, we know the renderer is either "django" or "django-components"
|
||||
root = file_path = Path(__file__).parent.parent
|
||||
if renderer == "django":
|
||||
if size == "lg":
|
||||
file_path = root / "tests" / "test_benchmark_django.py"
|
||||
else:
|
||||
file_path = root / "tests" / "test_benchmark_django_small.py"
|
||||
else:
|
||||
if size == "lg":
|
||||
file_path = root / "tests" / "test_benchmark_djc.py"
|
||||
else:
|
||||
file_path = root / "tests" / "test_benchmark_djc_small.py"
|
||||
|
||||
return file_path
|
||||
|
||||
|
||||
def _get_templating_script(
|
||||
renderer: TemplatingRenderer,
|
||||
size: TemplatingTestSize,
|
||||
context_mode: DjcContextMode,
|
||||
imports_only: bool,
|
||||
) -> str:
|
||||
if renderer == "none":
|
||||
return ""
|
||||
elif renderer not in ["django", "django-components"]:
|
||||
raise ValueError(f"Invalid renderer: {renderer}")
|
||||
|
||||
# At this point, we know the renderer is either "django" or "django-components"
|
||||
file_path = _get_templating_filepath(renderer, size)
|
||||
contents = file_path.read_text()
|
||||
|
||||
# The files with benchmarked code also have a section for testing them with pytest.
|
||||
# We remove that pytest section, so the script is only the benchmark code.
|
||||
contents = contents.split("# ----------- TESTS START ------------ #")[0]
|
||||
|
||||
if imports_only:
|
||||
# There is a benchmark test for measuring the time it takes to import the module.
|
||||
# For that, we exclude from the code everything AFTER this line
|
||||
contents = contents.split("# ----------- IMPORTS END ------------ #")[0]
|
||||
else:
|
||||
# Set the context mode by replacing variable in the script
|
||||
contents = re.sub(r"CONTEXT_MODE.*?\n", f"CONTEXT_MODE = '{context_mode}'\n", contents, count=1)
|
||||
|
||||
return contents
|
||||
|
||||
|
||||
def _get_templating_module(
|
||||
renderer: TemplatingRenderer,
|
||||
size: TemplatingTestSize,
|
||||
context_mode: DjcContextMode,
|
||||
imports_only: bool,
|
||||
) -> ModuleType:
|
||||
if renderer not in ("django", "django-components"):
|
||||
raise ValueError(f"Invalid renderer: {renderer}")
|
||||
|
||||
file_path = _get_templating_filepath(renderer, size)
|
||||
script = _get_templating_script(renderer, size, context_mode, imports_only)
|
||||
|
||||
# This makes it possible to import the module in the benchmark function
|
||||
# as `import test_templating`
|
||||
module = create_virtual_module("test_templating", script, str(file_path))
|
||||
return module
|
||||
|
||||
|
||||
# The `timeraw_` tests run in separate processes. But when running memory benchmarks,
|
||||
# the tested logic runs in the same process as the where we run the benchmark functions
|
||||
# (e.g. `peakmem_render_lg_first()`). Thus, the `peakmem_` functions have access to this file
|
||||
# when the tested logic runs.
|
||||
#
|
||||
# Secondly, `asv` doesn't offer any way to pass data from `setup` to actual test.
|
||||
#
|
||||
# And so we define this global, which, when running memory benchmarks, the `setup` function
|
||||
# populates. And then we trigger the actual render from within the test body.
|
||||
do_render = lambda: None # noqa: E731
|
||||
|
||||
|
||||
def setup_templating_memory_benchmark(
|
||||
renderer: TemplatingRenderer,
|
||||
size: TemplatingTestSize,
|
||||
test_type: TemplatingTestType,
|
||||
context_mode: DjcContextMode,
|
||||
imports_only: bool = False,
|
||||
):
|
||||
global do_render
|
||||
module = _get_templating_module(renderer, size, context_mode, imports_only)
|
||||
data = module.gen_render_data()
|
||||
render = module.render
|
||||
do_render = lambda: render(data) # noqa: E731
|
||||
|
||||
# Do the first render as part of setup if we're testing the subsequent renders
|
||||
if test_type == "subsequent":
|
||||
do_render()
|
||||
|
||||
|
||||
# The timing benchmarks run the actual code in a separate process, by using the `timeraw_` prefix.
|
||||
# As such, we don't actually load the code in this file. Instead, we only prepare a script (raw string)
|
||||
# that will be run in the new process.
|
||||
def prepare_templating_benchmark(
|
||||
renderer: TemplatingRenderer,
|
||||
size: TemplatingTestSize,
|
||||
test_type: TemplatingTestType,
|
||||
context_mode: DjcContextMode,
|
||||
imports_only: bool = False,
|
||||
):
|
||||
setup_script = _get_templating_script(renderer, size, context_mode, imports_only)
|
||||
|
||||
# If we're testing the startup time, then the setup is actually the tested code
|
||||
if test_type == "startup":
|
||||
return setup_script
|
||||
else:
|
||||
# Otherwise include also data generation as part of setup
|
||||
setup_script += "\n\n" "render_data = gen_render_data()\n"
|
||||
|
||||
# Do the first render as part of setup if we're testing the subsequent renders
|
||||
if test_type == "subsequent":
|
||||
setup_script += "render(render_data)\n"
|
||||
|
||||
benchmark_script = "render(render_data)\n"
|
||||
return benchmark_script, setup_script
|
||||
|
||||
|
||||
# - Group: django-components vs django
|
||||
# - time: djc vs django (startup lg)
|
||||
# - time: djc vs django (lg - FIRST)
|
||||
# - time: djc vs django (sm - FIRST)
|
||||
# - time: djc vs django (lg - SUBSEQUENT)
|
||||
# - time: djc vs django (sm - SUBSEQUENT)
|
||||
# - mem: djc vs django (lg - FIRST)
|
||||
# - mem: djc vs django (sm - FIRST)
|
||||
# - mem: djc vs django (lg - SUBSEQUENT)
|
||||
# - mem: djc vs django (sm - SUBSEQUENT)
|
||||
#
|
||||
# NOTE: While the name suggests we're comparing Django and Django-components, be aware that
|
||||
# in our "Django" tests, we still install and import django-components. We also use
|
||||
# django-components's `{% html_attrs %}` tag in the Django scenario. `{% html_attrs %}`
|
||||
# was used because the original sample code was from django-components.
|
||||
#
|
||||
# As such, these tests should seen not as "Using Django vs Using Components". But instead,
|
||||
# it should be "What is the relative cost of using Components?".
|
||||
#
|
||||
# As an example, the benchmarking for the startup time and memory usage is not comparing
|
||||
# two independent approaches. Rather, the test is checking if defining Components classes
|
||||
# is more expensive than vanilla Django templates.
|
||||
class DjangoComponentsVsDjangoTests:
|
||||
# Testing startup time (e.g. defining classes and templates)
|
||||
@benchmark(
|
||||
pretty_name="startup - large",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
)
|
||||
def timeraw_startup_lg(self, renderer: TemplatingRenderer):
|
||||
return prepare_templating_benchmark(renderer, "lg", "startup", "isolated")
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - first render",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_sm_first(self, renderer: TemplatingRenderer):
|
||||
return prepare_templating_benchmark(renderer, "sm", "first", "isolated")
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - second render",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_sm_subsequent(self, renderer: TemplatingRenderer):
|
||||
return prepare_templating_benchmark(renderer, "sm", "subsequent", "isolated")
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - first render",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
include_in_quick_benchmark=True,
|
||||
)
|
||||
def timeraw_render_lg_first(self, renderer: TemplatingRenderer):
|
||||
return prepare_templating_benchmark(renderer, "lg", "first", "isolated")
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - second render",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_lg_subsequent(self, renderer: TemplatingRenderer):
|
||||
return prepare_templating_benchmark(renderer, "lg", "subsequent", "isolated")
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - first render (mem)",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
setup=lambda renderer: setup_templating_memory_benchmark(renderer, "sm", "first", "isolated"),
|
||||
)
|
||||
def peakmem_render_sm_first(self, renderer: TemplatingRenderer):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - second render (mem)",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
setup=lambda renderer: setup_templating_memory_benchmark(renderer, "sm", "subsequent", "isolated"),
|
||||
)
|
||||
def peakmem_render_sm_subsequent(self, renderer: TemplatingRenderer):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - first render (mem)",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
setup=lambda renderer: setup_templating_memory_benchmark(renderer, "lg", "first", "isolated"),
|
||||
)
|
||||
def peakmem_render_lg_first(self, renderer: TemplatingRenderer):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - second render (mem)",
|
||||
group_name=DJC_VS_DJ_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"renderer": ["django", "django-components"],
|
||||
},
|
||||
setup=lambda renderer: setup_templating_memory_benchmark(renderer, "lg", "subsequent", "isolated"),
|
||||
)
|
||||
def peakmem_render_lg_subsequent(self, renderer: TemplatingRenderer):
|
||||
do_render()
|
||||
|
||||
|
||||
# - Group: Django-components "isolated" vs "django" modes
|
||||
# - time: Isolated vs django djc (startup lg)
|
||||
# - time: Isolated vs django djc (lg - FIRST)
|
||||
# - time: Isolated vs django djc (sm - FIRST)
|
||||
# - time: Isolated vs django djc (lg - SUBSEQUENT)
|
||||
# - time: Isolated vs django djc (sm - SUBSEQUENT)
|
||||
# - mem: Isolated vs django djc (lg - FIRST)
|
||||
# - mem: Isolated vs django djc (sm - FIRST)
|
||||
# - mem: Isolated vs django djc (lg - SUBSEQUENT)
|
||||
# - mem: Isolated vs django djc (sm - SUBSEQUENT)
|
||||
class IsolatedVsDjangoContextModesTests:
|
||||
# Testing startup time (e.g. defining classes and templates)
|
||||
@benchmark(
|
||||
pretty_name="startup - large",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
)
|
||||
def timeraw_startup_lg(self, context_mode: DjcContextMode):
|
||||
return prepare_templating_benchmark("django-components", "lg", "startup", context_mode)
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - first render",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_sm_first(self, context_mode: DjcContextMode):
|
||||
return prepare_templating_benchmark("django-components", "sm", "first", context_mode)
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - second render",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_sm_subsequent(self, context_mode: DjcContextMode):
|
||||
return prepare_templating_benchmark("django-components", "sm", "subsequent", context_mode)
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - first render",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_lg_first(self, context_mode: DjcContextMode):
|
||||
return prepare_templating_benchmark("django-components", "lg", "first", context_mode)
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - second render",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
)
|
||||
def timeraw_render_lg_subsequent(self, context_mode: DjcContextMode):
|
||||
return prepare_templating_benchmark("django-components", "lg", "subsequent", context_mode)
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - first render (mem)",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
setup=lambda context_mode: setup_templating_memory_benchmark("django-components", "sm", "first", context_mode),
|
||||
)
|
||||
def peakmem_render_sm_first(self, context_mode: DjcContextMode):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - small - second render (mem)",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
setup=lambda context_mode: setup_templating_memory_benchmark(
|
||||
"django-components",
|
||||
"sm",
|
||||
"subsequent",
|
||||
context_mode,
|
||||
),
|
||||
)
|
||||
def peakmem_render_sm_subsequent(self, context_mode: DjcContextMode):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - first render (mem)",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
setup=lambda context_mode: setup_templating_memory_benchmark(
|
||||
"django-components",
|
||||
"lg",
|
||||
"first",
|
||||
context_mode,
|
||||
),
|
||||
)
|
||||
def peakmem_render_lg_first(self, context_mode: DjcContextMode):
|
||||
do_render()
|
||||
|
||||
@benchmark(
|
||||
pretty_name="render - large - second render (mem)",
|
||||
group_name=DJC_ISOLATED_VS_NON_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
params={
|
||||
"context_mode": ["isolated", "django"],
|
||||
},
|
||||
setup=lambda context_mode: setup_templating_memory_benchmark(
|
||||
"django-components",
|
||||
"lg",
|
||||
"subsequent",
|
||||
context_mode,
|
||||
),
|
||||
)
|
||||
def peakmem_render_lg_subsequent(self, context_mode: DjcContextMode):
|
||||
do_render()
|
||||
|
||||
|
||||
class OtherTests:
|
||||
@benchmark(
|
||||
pretty_name="import time",
|
||||
group_name=OTHER_GROUP,
|
||||
number=1,
|
||||
rounds=5,
|
||||
)
|
||||
def timeraw_import_time(self):
|
||||
return prepare_templating_benchmark("django-components", "lg", "startup", "isolated", imports_only=True)
|
|
@ -1,176 +0,0 @@
|
|||
from time import perf_counter
|
||||
|
||||
from django.template import Context, Template
|
||||
|
||||
from django_components import Component, registry, types
|
||||
from django_components.dependencies import CSS_DEPENDENCY_PLACEHOLDER, JS_DEPENDENCY_PLACEHOLDER
|
||||
from tests.django_test_setup import * # NOQA
|
||||
from tests.testutils import BaseTestCase, create_and_process_template_response
|
||||
|
||||
|
||||
class SlottedComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<custom-template>
|
||||
<header>{% slot "header" %}Default header{% endslot %}</header>
|
||||
<main>{% slot "main" %}Default main{% endslot %}</main>
|
||||
<footer>{% slot "footer" %}Default footer{% endslot %}</footer>
|
||||
</custom-template>
|
||||
"""
|
||||
|
||||
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
Variable: <strong>{{ variable }}</strong>
|
||||
"""
|
||||
|
||||
def get_context_data(self, variable, variable2="default"):
|
||||
return {
|
||||
"variable": variable,
|
||||
"variable2": variable2,
|
||||
}
|
||||
|
||||
class Media:
|
||||
css = {"all": ["style.css"]}
|
||||
js = ["script.js"]
|
||||
|
||||
|
||||
class BreadcrumbComponent(Component):
|
||||
template: types.django_html = """
|
||||
<div class="breadcrumb-container">
|
||||
<nav class="breadcrumbs">
|
||||
<ol typeof="BreadcrumbList" vocab="https://schema.org/" aria-label="breadcrumbs">
|
||||
{% for label, url in links %}
|
||||
<li property="itemListElement" typeof="ListItem">
|
||||
<a class="breadcrumb-current-page" property="item" typeof="WebPage" href="{{ url }}">
|
||||
<span property="name">{{ label }}</span>
|
||||
</a>
|
||||
<meta property="position" content="4">
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
"""
|
||||
|
||||
LINKS = [
|
||||
(
|
||||
"https://developer.mozilla.org/en-US/docs/Learn",
|
||||
"Learn web development",
|
||||
),
|
||||
(
|
||||
"https://developer.mozilla.org/en-US/docs/Learn/HTML",
|
||||
"Structuring the web with HTML",
|
||||
),
|
||||
(
|
||||
"https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML",
|
||||
"Introduction to HTML",
|
||||
),
|
||||
(
|
||||
"https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Document_and_website_structure",
|
||||
"Document and website structure",
|
||||
),
|
||||
]
|
||||
|
||||
def get_context_data(self, items):
|
||||
if items > 4:
|
||||
items = 4
|
||||
elif items < 0:
|
||||
items = 0
|
||||
return {"links": self.LINKS[: items - 1]}
|
||||
|
||||
class Media:
|
||||
css = {"all": ["test.css"]}
|
||||
js = ["test.js"]
|
||||
|
||||
|
||||
EXPECTED_CSS = """<link href="test.css" media="all" rel="stylesheet">"""
|
||||
EXPECTED_JS = """<script src="test.js"></script>"""
|
||||
|
||||
|
||||
class RenderBenchmarks(BaseTestCase):
|
||||
def setUp(self):
|
||||
registry.clear()
|
||||
registry.register("test_component", SlottedComponent)
|
||||
registry.register("inner_component", SimpleComponent)
|
||||
registry.register("breadcrumb_component", BreadcrumbComponent)
|
||||
|
||||
@staticmethod
|
||||
def timed_loop(func, iterations=1000):
|
||||
"""Run func iterations times, and return the time in ms per iteration."""
|
||||
start_time = perf_counter()
|
||||
for _ in range(iterations):
|
||||
func()
|
||||
end_time = perf_counter()
|
||||
total_elapsed = end_time - start_time # NOQA
|
||||
return total_elapsed * 1000 / iterations
|
||||
|
||||
def test_render_time_for_small_component(self):
|
||||
template_str: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component 'test_component' %}
|
||||
{% slot "header" %}
|
||||
{% component 'inner_component' variable='foo' %}{% endcomponent %}
|
||||
{% endslot %}
|
||||
{% endcomponent %}
|
||||
"""
|
||||
template = Template(template_str)
|
||||
|
||||
print(f"{self.timed_loop(lambda: template.render(Context({})))} ms per iteration")
|
||||
|
||||
def test_middleware_time_with_dependency_for_small_page(self):
|
||||
template_str: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component_js_dependencies %}
|
||||
{% component_css_dependencies %}
|
||||
{% component 'test_component' %}
|
||||
{% slot "header" %}
|
||||
{% component 'inner_component' variable='foo' %}{% endcomponent %}
|
||||
{% endslot %}
|
||||
{% endcomponent %}
|
||||
"""
|
||||
template = Template(template_str)
|
||||
# Sanity tests
|
||||
response_content = create_and_process_template_response(template)
|
||||
self.assertNotIn(CSS_DEPENDENCY_PLACEHOLDER, response_content)
|
||||
self.assertNotIn(JS_DEPENDENCY_PLACEHOLDER, response_content)
|
||||
self.assertIn("style.css", response_content)
|
||||
self.assertIn("script.js", response_content)
|
||||
|
||||
without_middleware = self.timed_loop(
|
||||
lambda: create_and_process_template_response(template, use_middleware=False)
|
||||
)
|
||||
with_middleware = self.timed_loop(lambda: create_and_process_template_response(template, use_middleware=True))
|
||||
|
||||
print("Small page middleware test")
|
||||
self.report_results(with_middleware, without_middleware)
|
||||
|
||||
def test_render_time_with_dependency_for_large_page(self):
|
||||
from django.template.loader import get_template
|
||||
|
||||
template = get_template("mdn_complete_page.html")
|
||||
response_content = create_and_process_template_response(template, {})
|
||||
self.assertNotIn(CSS_DEPENDENCY_PLACEHOLDER, response_content)
|
||||
self.assertNotIn(JS_DEPENDENCY_PLACEHOLDER, response_content)
|
||||
self.assertIn("test.css", response_content)
|
||||
self.assertIn("test.js", response_content)
|
||||
|
||||
without_middleware = self.timed_loop(
|
||||
lambda: create_and_process_template_response(template, {}, use_middleware=False)
|
||||
)
|
||||
with_middleware = self.timed_loop(
|
||||
lambda: create_and_process_template_response(template, {}, use_middleware=True)
|
||||
)
|
||||
|
||||
print("Large page middleware test")
|
||||
self.report_results(with_middleware, without_middleware)
|
||||
|
||||
@staticmethod
|
||||
def report_results(with_middleware, without_middleware):
|
||||
print(f"Middleware active\t\t{with_middleware:.3f} ms per iteration")
|
||||
print(f"Middleware inactive\t{without_middleware:.3f} ms per iteration")
|
||||
time_difference = with_middleware - without_middleware
|
||||
if without_middleware > with_middleware:
|
||||
print(f"Decrease of {-100 * time_difference / with_middleware:.2f}%")
|
||||
else:
|
||||
print(f"Increase of {100 * time_difference / without_middleware:.2f}%")
|
29
benchmarks/monkeypatch_asv.py
Normal file
29
benchmarks/monkeypatch_asv.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from asv_runner.benchmarks.timeraw import TimerawBenchmark, _SeparateProcessTimer
|
||||
|
||||
|
||||
# Fix for https://github.com/airspeed-velocity/asv_runner/pull/44
|
||||
def _get_timer(self, *param):
|
||||
"""
|
||||
Returns a timer that runs the benchmark function in a separate process.
|
||||
|
||||
#### Parameters
|
||||
**param** (`tuple`)
|
||||
: The parameters to pass to the benchmark function.
|
||||
|
||||
#### Returns
|
||||
**timer** (`_SeparateProcessTimer`)
|
||||
: A timer that runs the function in a separate process.
|
||||
"""
|
||||
if param:
|
||||
|
||||
def func():
|
||||
# ---------- OUR CHANGES: ADDED RETURN STATEMENT ----------
|
||||
return self.func(*param)
|
||||
# ---------- OUR CHANGES END ----------
|
||||
|
||||
else:
|
||||
func = self.func
|
||||
return _SeparateProcessTimer(func)
|
||||
|
||||
|
||||
TimerawBenchmark._get_timer = _get_timer
|
66
benchmarks/monkeypatch_asv_ci.txt
Normal file
66
benchmarks/monkeypatch_asv_ci.txt
Normal file
|
@ -0,0 +1,66 @@
|
|||
# ------------ FIX FOR #45 ------------
|
||||
# See https://github.com/airspeed-velocity/asv_runner/issues/45
|
||||
# This fix is applied in CI in the `benchmark.yml` file.
|
||||
# This file is intentionally named `monkeypatch_asv_ci.txt` to avoid being
|
||||
# loaded as a python file by `asv`.
|
||||
# -------------------------------------
|
||||
|
||||
def timeit(self, number):
|
||||
"""
|
||||
Run the function's code `number` times in a separate Python process, and
|
||||
return the execution time.
|
||||
|
||||
#### Parameters
|
||||
**number** (`int`)
|
||||
: The number of times to execute the function's code.
|
||||
|
||||
#### Returns
|
||||
**time** (`float`)
|
||||
: The time it took to execute the function's code `number` times.
|
||||
|
||||
#### Notes
|
||||
The function's code is executed in a separate Python process to avoid
|
||||
interference from the parent process. The function can return either a
|
||||
single string of code to be executed, or a tuple of two strings: the
|
||||
code to be executed and the setup code to be run before timing.
|
||||
"""
|
||||
stmt = self.func()
|
||||
if isinstance(stmt, tuple):
|
||||
stmt, setup = stmt
|
||||
else:
|
||||
setup = ""
|
||||
stmt = textwrap.dedent(stmt)
|
||||
setup = textwrap.dedent(setup)
|
||||
stmt = stmt.replace(r'"""', r"\"\"\"")
|
||||
setup = setup.replace(r'"""', r"\"\"\"")
|
||||
|
||||
# TODO
|
||||
# -----------ORIGINAL CODE-----------
|
||||
# code = self.subprocess_tmpl.format(stmt=stmt, setup=setup, number=number)
|
||||
|
||||
# res = subprocess.check_output([sys.executable, "-c", code])
|
||||
# return float(res.strip())
|
||||
|
||||
# -----------NEW CODE-----------
|
||||
code = self.subprocess_tmpl.format(stmt=stmt, setup=setup, number=number)
|
||||
|
||||
evaler = textwrap.dedent(
|
||||
"""
|
||||
import sys
|
||||
code = sys.stdin.read()
|
||||
exec(code)
|
||||
"""
|
||||
)
|
||||
|
||||
proc = subprocess.Popen([sys.executable, "-c", evaler],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = proc.communicate(input=code.encode("utf-8"))
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError(f"Subprocess failed: {stderr.decode()}")
|
||||
return float(stdout.decode("utf-8").strip())
|
||||
|
||||
_SeparateProcessTimer.timeit = timeit
|
||||
|
||||
# ------------ END FIX #45 ------------
|
99
benchmarks/utils.py
Normal file
99
benchmarks/utils.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
import os
|
||||
import sys
|
||||
from importlib.abc import Loader
|
||||
from importlib.util import spec_from_loader, module_from_spec
|
||||
from types import ModuleType
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
|
||||
# NOTE: benchmark_name constraints:
|
||||
# - MUST BE UNIQUE
|
||||
# - MUST NOT CONTAIN `-`
|
||||
# - MUST START WITH `time_`, `mem_`, `peakmem_`
|
||||
# See https://github.com/airspeed-velocity/asv/pull/1470
|
||||
def benchmark(
|
||||
*,
|
||||
pretty_name: Optional[str] = None,
|
||||
timeout: Optional[int] = None,
|
||||
group_name: Optional[str] = None,
|
||||
params: Optional[Dict[str, List[Any]]] = None,
|
||||
number: Optional[int] = None,
|
||||
min_run_count: Optional[int] = None,
|
||||
include_in_quick_benchmark: bool = False,
|
||||
**kwargs,
|
||||
):
|
||||
def decorator(func):
|
||||
# For pull requests, we want to run benchmarks only for a subset of tests,
|
||||
# because the full set of tests takes about 10 minutes to run (5 min per commit).
|
||||
# This is done by setting DJC_BENCHMARK_QUICK=1 in the environment.
|
||||
if os.getenv("DJC_BENCHMARK_QUICK") and not include_in_quick_benchmark:
|
||||
# By setting the benchmark name to something that does NOT start with
|
||||
# valid prefixes like `time_`, `mem_`, or `peakmem_`, this function will be ignored by asv.
|
||||
func.benchmark_name = "noop"
|
||||
return func
|
||||
|
||||
# "group_name" is our custom field, which we actually convert to asv's "benchmark_name"
|
||||
if group_name is not None:
|
||||
benchmark_name = f"{group_name}.{func.__name__}"
|
||||
func.benchmark_name = benchmark_name
|
||||
|
||||
# Also "params" is custom, so we normalize it to "params" and "param_names"
|
||||
if params is not None:
|
||||
func.params, func.param_names = list(params.values()), list(params.keys())
|
||||
|
||||
if pretty_name is not None:
|
||||
func.pretty_name = pretty_name
|
||||
if timeout is not None:
|
||||
func.timeout = timeout
|
||||
if number is not None:
|
||||
func.number = number
|
||||
if min_run_count is not None:
|
||||
func.min_run_count = min_run_count
|
||||
|
||||
# Additional, untyped kwargs
|
||||
for k, v in kwargs.items():
|
||||
setattr(func, k, v)
|
||||
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class VirtualModuleLoader(Loader):
|
||||
def __init__(self, code_string):
|
||||
self.code_string = code_string
|
||||
|
||||
def exec_module(self, module):
|
||||
exec(self.code_string, module.__dict__)
|
||||
|
||||
|
||||
def create_virtual_module(name: str, code_string: str, file_path: str) -> ModuleType:
|
||||
"""
|
||||
To avoid the headaches of importing the tested code from another diretory,
|
||||
we create a "virtual" module that we can import from anywhere.
|
||||
|
||||
E.g.
|
||||
```py
|
||||
from benchmarks.utils import create_virtual_module
|
||||
|
||||
create_virtual_module("my_module", "print('Hello, world!')", __file__)
|
||||
|
||||
# Now you can import my_module from anywhere
|
||||
import my_module
|
||||
```
|
||||
"""
|
||||
# Create the module specification
|
||||
spec = spec_from_loader(name, VirtualModuleLoader(code_string))
|
||||
|
||||
# Create the module
|
||||
module = module_from_spec(spec) # type: ignore[arg-type]
|
||||
module.__file__ = file_path
|
||||
module.__name__ = name
|
||||
|
||||
# Add it to sys.modules
|
||||
sys.modules[name] = module
|
||||
|
||||
# Execute the module
|
||||
spec.loader.exec_module(module) # type: ignore[union-attr]
|
||||
|
||||
return module
|
10
docs/.nav.yml
Normal file
10
docs/.nav.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
# For navigation content inspo see Pydantic https://docs.pydantic.dev/latest
|
||||
#
|
||||
# `.nav.yml` is provided by https://lukasgeiter.github.io/mkdocs-awesome-nav
|
||||
nav:
|
||||
- overview
|
||||
- Getting Started: getting_started
|
||||
- concepts
|
||||
- guides
|
||||
- API Documentation: reference
|
||||
- Release Notes: release_notes.md
|
|
@ -1,11 +0,0 @@
|
|||
<!-- See Pydantic for inspo https://docs.pydantic.dev/latest -->
|
||||
- [Get Started](overview/)
|
||||
- Concepts
|
||||
- [Getting started](concepts/getting_started/)
|
||||
- [Fundamentals](concepts/fundamentals/)
|
||||
- [Advanced](concepts/advanced/)
|
||||
- Guides
|
||||
- [Setup](guides/setup/)
|
||||
- [Dev guides](guides/devguides/)
|
||||
- [API Documentation](reference/)
|
||||
- [Release notes](release_notes.md)
|
161
docs/benchmarks/asv.css
Normal file
161
docs/benchmarks/asv.css
Normal file
|
@ -0,0 +1,161 @@
|
|||
/* Basic navigation */
|
||||
|
||||
.asv-navigation {
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
nav ul li.active a {
|
||||
height: 52px;
|
||||
}
|
||||
|
||||
nav li.active span.navbar-brand {
|
||||
background-color: #e7e7e7;
|
||||
height: 52px;
|
||||
}
|
||||
|
||||
nav li.active span.navbar-brand:hover {
|
||||
background-color: #e7e7e7;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-link {
|
||||
color: #2458D9;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.panel {
|
||||
margin-bottom: 4px;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
border-radius: 0;
|
||||
border-top-left-radius: 3px;
|
||||
border-top-right-radius: 3px;
|
||||
}
|
||||
|
||||
.panel-default>.panel-heading,
|
||||
.panel-heading {
|
||||
font-size: 12px;
|
||||
font-weight:bold;
|
||||
padding: 2px;
|
||||
text-align: center;
|
||||
border-top-left-radius: 3px;
|
||||
border-top-right-radius: 3px;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.btn,
|
||||
.btn-group,
|
||||
.btn-group-vertical>.btn:first-child,
|
||||
.btn-group-vertical>.btn:last-child:not(:first-child),
|
||||
.btn-group-vertical>.btn:last-child {
|
||||
border: none;
|
||||
border-radius: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.btn-default:focus, .btn-default:active, .btn-default.active {
|
||||
border: none;
|
||||
color: #fff;
|
||||
background-color: #99bfcd;
|
||||
}
|
||||
|
||||
#range {
|
||||
font-family: monospace;
|
||||
text-align: center;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border: none;
|
||||
border-radius: 0px;
|
||||
font-size: 12px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.tooltip-inner {
|
||||
min-width: 100px;
|
||||
max-width: 800px;
|
||||
text-align: left;
|
||||
white-space: pre-wrap;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
/* Benchmark tree */
|
||||
|
||||
.nav-list {
|
||||
font-size: 12px;
|
||||
padding: 0;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.nav-list>li {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.nav-list>li>a {
|
||||
padding: 0;
|
||||
padding-left: 5px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.nav-list>li>a:focus {
|
||||
color: #fff;
|
||||
background-color: #99bfcd;
|
||||
box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
|
||||
}
|
||||
|
||||
.nav-list>li>.nav-header {
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.caret-right {
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin-left: 2px;
|
||||
vertical-align: middle;
|
||||
border-left: 4px solid;
|
||||
border-bottom: 4px solid transparent;
|
||||
border-top: 4px solid transparent;
|
||||
}
|
||||
|
||||
/* Summary page */
|
||||
|
||||
.benchmark-group > h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.benchmark-container {
|
||||
width: 300px;
|
||||
height: 116px;
|
||||
padding: 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.benchmark-container:hover {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.benchmark-plot {
|
||||
width: 292px;
|
||||
height: 88px;
|
||||
}
|
||||
|
||||
.benchmark-text {
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
width: 292px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#extra-buttons {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
#extra-buttons a {
|
||||
border: solid 1px #ccc;
|
||||
}
|
525
docs/benchmarks/asv.js
Normal file
525
docs/benchmarks/asv.js
Normal file
|
@ -0,0 +1,525 @@
|
|||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
/* GLOBAL STATE */
|
||||
/* The index.json content as returned from the server */
|
||||
var main_timestamp = '';
|
||||
var main_json = {};
|
||||
/* Extra pages: {name: show_function} */
|
||||
var loaded_pages = {};
|
||||
/* Previous window scroll positions */
|
||||
var window_scroll_positions = {};
|
||||
/* Previous window hash location */
|
||||
var window_last_location = null;
|
||||
/* Graph data cache */
|
||||
var graph_cache = {};
|
||||
var graph_cache_max_size = 5;
|
||||
|
||||
var colors = [
|
||||
'#247AAD',
|
||||
'#E24A33',
|
||||
'#988ED5',
|
||||
'#777777',
|
||||
'#FBC15E',
|
||||
'#8EBA42',
|
||||
'#FFB5B8'
|
||||
];
|
||||
|
||||
var time_units = [
|
||||
['ps', 'picoseconds', 0.000000000001],
|
||||
['ns', 'nanoseconds', 0.000000001],
|
||||
['μs', 'microseconds', 0.000001],
|
||||
['ms', 'milliseconds', 0.001],
|
||||
['s', 'seconds', 1],
|
||||
['m', 'minutes', 60],
|
||||
['h', 'hours', 60 * 60],
|
||||
['d', 'days', 60 * 60 * 24],
|
||||
['w', 'weeks', 60 * 60 * 24 * 7],
|
||||
['y', 'years', 60 * 60 * 24 * 7 * 52],
|
||||
['C', 'centuries', 60 * 60 * 24 * 7 * 52 * 100]
|
||||
];
|
||||
|
||||
var mem_units = [
|
||||
['', 'bytes', 1],
|
||||
['k', 'kilobytes', 1000],
|
||||
['M', 'megabytes', 1000000],
|
||||
['G', 'gigabytes', 1000000000],
|
||||
['T', 'terabytes', 1000000000000]
|
||||
];
|
||||
|
||||
function pretty_second(x) {
|
||||
for (var i = 0; i < time_units.length - 1; ++i) {
|
||||
if (Math.abs(x) < time_units[i+1][2]) {
|
||||
return (x / time_units[i][2]).toFixed(3) + time_units[i][0];
|
||||
}
|
||||
}
|
||||
|
||||
return 'inf';
|
||||
}
|
||||
|
||||
function pretty_byte(x) {
|
||||
for (var i = 0; i < mem_units.length - 1; ++i) {
|
||||
if (Math.abs(x) < mem_units[i+1][2]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
return x + '';
|
||||
}
|
||||
return (x / mem_units[i][2]).toFixed(3) + mem_units[i][0];
|
||||
}
|
||||
|
||||
function pretty_unit(x, unit) {
|
||||
if (unit == "seconds") {
|
||||
return pretty_second(x);
|
||||
}
|
||||
else if (unit == "bytes") {
|
||||
return pretty_byte(x);
|
||||
}
|
||||
else if (unit && unit != "unit") {
|
||||
return '' + x.toPrecision(3) + ' ' + unit;
|
||||
}
|
||||
else {
|
||||
return '' + x.toPrecision(3);
|
||||
}
|
||||
}
|
||||
|
||||
function pad_left(s, c, num) {
|
||||
s = '' + s;
|
||||
while (s.length < num) {
|
||||
s = c + s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function format_date_yyyymmdd(date) {
|
||||
return (pad_left(date.getFullYear(), '0', 4)
|
||||
+ '-' + pad_left(date.getMonth() + 1, '0', 2)
|
||||
+ '-' + pad_left(date.getDate(), '0', 2));
|
||||
}
|
||||
|
||||
function format_date_yyyymmdd_hhmm(date) {
|
||||
return (format_date_yyyymmdd(date) + ' '
|
||||
+ pad_left(date.getHours(), '0', 2)
|
||||
+ ':' + pad_left(date.getMinutes(), '0', 2));
|
||||
}
|
||||
|
||||
/* Convert a flat index to permutation to the corresponding value */
|
||||
function param_selection_from_flat_idx(params, idx) {
|
||||
var selection = [];
|
||||
if (idx < 0) {
|
||||
idx = 0;
|
||||
}
|
||||
for (var k = params.length-1; k >= 0; --k) {
|
||||
var j = idx % params[k].length;
|
||||
selection.unshift([j]);
|
||||
idx = (idx - j) / params[k].length;
|
||||
}
|
||||
selection.unshift([null]);
|
||||
return selection;
|
||||
}
|
||||
|
||||
/* Convert a benchmark parameter value from their native Python
|
||||
repr format to a number or a string, ready for presentation */
|
||||
function convert_benchmark_param_value(value_repr) {
|
||||
var match = Number(value_repr);
|
||||
if (!isNaN(match)) {
|
||||
return match;
|
||||
}
|
||||
|
||||
/* Python str */
|
||||
match = value_repr.match(/^'(.+)'$/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
/* Python unicode */
|
||||
match = value_repr.match(/^u'(.+)'$/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
/* Python class */
|
||||
match = value_repr.match(/^<class '(.+)'>$/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return value_repr;
|
||||
}
|
||||
|
||||
/* Convert loaded graph data to a format flot understands, by
|
||||
treating either time or one of the parameters as x-axis,
|
||||
and selecting only one value of the remaining axes */
|
||||
function filter_graph_data(raw_series, x_axis, other_indices, params) {
|
||||
if (params.length == 0) {
|
||||
/* Simple time series */
|
||||
return raw_series;
|
||||
}
|
||||
|
||||
/* Compute position of data entry in the results list,
|
||||
and stride corresponding to plot x-axis parameter */
|
||||
var stride = 1;
|
||||
var param_stride = 0;
|
||||
var param_idx = 0;
|
||||
for (var k = params.length - 1; k >= 0; --k) {
|
||||
if (k == x_axis - 1) {
|
||||
param_stride = stride;
|
||||
}
|
||||
else {
|
||||
param_idx += other_indices[k + 1] * stride;
|
||||
}
|
||||
stride *= params[k].length;
|
||||
}
|
||||
|
||||
if (x_axis == 0) {
|
||||
/* x-axis is time axis */
|
||||
var series = new Array(raw_series.length);
|
||||
for (var k = 0; k < raw_series.length; ++k) {
|
||||
if (raw_series[k][1] === null) {
|
||||
series[k] = [raw_series[k][0], null];
|
||||
} else {
|
||||
series[k] = [raw_series[k][0],
|
||||
raw_series[k][1][param_idx]];
|
||||
}
|
||||
}
|
||||
return series;
|
||||
}
|
||||
else {
|
||||
/* x-axis is some parameter axis */
|
||||
var time_idx = null;
|
||||
if (other_indices[0] === null) {
|
||||
time_idx = raw_series.length - 1;
|
||||
}
|
||||
else {
|
||||
/* Need to search for the correct time value */
|
||||
for (var k = 0; k < raw_series.length; ++k) {
|
||||
if (raw_series[k][0] == other_indices[0]) {
|
||||
time_idx = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (time_idx === null) {
|
||||
/* No data points */
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
var x_values = params[x_axis - 1];
|
||||
var series = new Array(x_values.length);
|
||||
for (var k = 0; k < x_values.length; ++k) {
|
||||
if (raw_series[time_idx][1] === null) {
|
||||
series[k] = [convert_benchmark_param_value(x_values[k]),
|
||||
null];
|
||||
}
|
||||
else {
|
||||
series[k] = [convert_benchmark_param_value(x_values[k]),
|
||||
raw_series[time_idx][1][param_idx]];
|
||||
}
|
||||
param_idx += param_stride;
|
||||
}
|
||||
return series;
|
||||
}
|
||||
}
|
||||
|
||||
function filter_graph_data_idx(raw_series, x_axis, flat_idx, params) {
|
||||
var selection = param_selection_from_flat_idx(params, flat_idx);
|
||||
var flat_selection = [];
|
||||
$.each(selection, function(i, v) {
|
||||
flat_selection.push(v[0]);
|
||||
});
|
||||
return filter_graph_data(raw_series, x_axis, flat_selection, params);
|
||||
}
|
||||
|
||||
/* Escape special characters in graph item file names.
|
||||
The implementation must match asv.util.sanitize_filename */
|
||||
function sanitize_filename(name) {
|
||||
var bad_re = /[<>:"\/\\^|?*\x00-\x1f]/g;
|
||||
var bad_names = ["CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3",
|
||||
"COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1",
|
||||
"LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8",
|
||||
"LPT9"];
|
||||
name = name.replace(bad_re, "_");
|
||||
if (bad_names.indexOf(name.toUpperCase()) != -1) {
|
||||
name = name + "_";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/* Given a specific group of parameters, generate the URL to
|
||||
use to load that graph.
|
||||
The implementation must match asv.graph.Graph.get_file_path
|
||||
*/
|
||||
function graph_to_path(benchmark_name, state) {
|
||||
var parts = [];
|
||||
$.each(state, function(key, value) {
|
||||
var part;
|
||||
if (value === null) {
|
||||
part = key + "-null";
|
||||
} else if (value) {
|
||||
part = key + "-" + value;
|
||||
} else {
|
||||
part = key;
|
||||
}
|
||||
parts.push(sanitize_filename('' + part));
|
||||
});
|
||||
parts.sort();
|
||||
parts.splice(0, 0, "graphs");
|
||||
parts.push(sanitize_filename(benchmark_name));
|
||||
|
||||
/* Escape URI components */
|
||||
parts = $.map(parts, function (val) { return encodeURIComponent(val); });
|
||||
return parts.join('/') + ".json";
|
||||
}
|
||||
|
||||
/*
|
||||
Load and cache graph data (on javascript side)
|
||||
*/
|
||||
function load_graph_data(url, success, failure) {
|
||||
var dfd = $.Deferred();
|
||||
if (graph_cache[url]) {
|
||||
setTimeout(function() {
|
||||
dfd.resolve(graph_cache[url]);
|
||||
}, 1);
|
||||
}
|
||||
else {
|
||||
$.ajax({
|
||||
url: url + '?timestamp=' + $.asv.main_timestamp,
|
||||
dataType: "json",
|
||||
cache: true
|
||||
}).done(function(data) {
|
||||
if (Object.keys(graph_cache).length > graph_cache_max_size) {
|
||||
$.each(Object.keys(graph_cache), function (i, key) {
|
||||
delete graph_cache[key];
|
||||
});
|
||||
}
|
||||
graph_cache[url] = data;
|
||||
dfd.resolve(data);
|
||||
}).fail(function() {
|
||||
dfd.reject();
|
||||
});
|
||||
}
|
||||
return dfd.promise();
|
||||
}
|
||||
|
||||
/*
|
||||
Parse hash string, assuming format similar to standard URL
|
||||
query strings
|
||||
*/
|
||||
function parse_hash_string(str) {
|
||||
var info = {location: [''], params: {}};
|
||||
|
||||
if (str && str[0] == '#') {
|
||||
str = str.slice(1);
|
||||
}
|
||||
if (str && str[0] == '/') {
|
||||
str = str.slice(1);
|
||||
}
|
||||
|
||||
var match = str.match(/^([^?]*?)\?/);
|
||||
if (match) {
|
||||
info['location'] = decodeURIComponent(match[1]).replace(/\/+/, '/').split('/');
|
||||
var rest = str.slice(match[1].length+1);
|
||||
var parts = rest.split('&');
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
var part = parts[i].split('=');
|
||||
if (part.length != 2) {
|
||||
continue;
|
||||
}
|
||||
var key = decodeURIComponent(part[0].replace(/\+/g, " "));
|
||||
var value = decodeURIComponent(part[1].replace(/\+/g, " "));
|
||||
if (value == '[none]') {
|
||||
value = null;
|
||||
}
|
||||
if (info['params'][key] === undefined) {
|
||||
info['params'][key] = [value];
|
||||
}
|
||||
else {
|
||||
info['params'][key].push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
info['location'] = decodeURIComponent(str).replace(/\/+/, '/').split('/');
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/*
|
||||
Generate a hash string, inverse of parse_hash_string
|
||||
*/
|
||||
function format_hash_string(info) {
|
||||
var parts = info['params'];
|
||||
var str = '#' + info['location'];
|
||||
|
||||
if (parts) {
|
||||
str = str + '?';
|
||||
var first = true;
|
||||
$.each(parts, function (key, values) {
|
||||
$.each(values, function (idx, value) {
|
||||
if (!first) {
|
||||
str = str + '&';
|
||||
}
|
||||
if (value === null) {
|
||||
value = '[none]';
|
||||
}
|
||||
str = str + encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
||||
first = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
Dealing with sub-pages
|
||||
*/
|
||||
|
||||
function show_page(name, params) {
|
||||
if (loaded_pages[name] !== undefined) {
|
||||
$("#nav ul li.active").removeClass('active');
|
||||
$("#nav-li-" + name).addClass('active');
|
||||
$("#graph-display").hide();
|
||||
$("#summarygrid-display").hide();
|
||||
$("#summarylist-display").hide();
|
||||
$('#regressions-display').hide();
|
||||
$('.tooltip').remove();
|
||||
loaded_pages[name](params);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function hashchange() {
|
||||
var info = parse_hash_string(window.location.hash);
|
||||
|
||||
/* Keep track of window scroll position; makes the back-button work */
|
||||
var old_scroll_pos = window_scroll_positions[info.location.join('/')];
|
||||
window_scroll_positions[window_last_location] = $(window).scrollTop();
|
||||
window_last_location = info.location.join('/');
|
||||
|
||||
/* Redirect to correct handler */
|
||||
if (show_page(info.location, info.params)) {
|
||||
/* show_page does the work */
|
||||
}
|
||||
else {
|
||||
/* Display benchmark page */
|
||||
info.params['benchmark'] = info.location[0];
|
||||
show_page('graphdisplay', info.params);
|
||||
}
|
||||
|
||||
/* Scroll back to previous position, if any */
|
||||
if (old_scroll_pos !== undefined) {
|
||||
$(window).scrollTop(old_scroll_pos);
|
||||
}
|
||||
}
|
||||
|
||||
function get_commit_hash(revision) {
|
||||
var commit_hash = main_json.revision_to_hash[revision];
|
||||
if (commit_hash) {
|
||||
// Return printable commit hash
|
||||
commit_hash = commit_hash.slice(0, main_json.hash_length);
|
||||
}
|
||||
return commit_hash;
|
||||
}
|
||||
|
||||
function get_revision(commit_hash) {
|
||||
var rev = null;
|
||||
$.each(main_json.revision_to_hash, function(revision, full_commit_hash) {
|
||||
if (full_commit_hash.startsWith(commit_hash)) {
|
||||
rev = revision;
|
||||
// break the $.each loop
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return rev;
|
||||
}
|
||||
|
||||
function init_index() {
|
||||
/* Fetch the main index.json and then set up the page elements
|
||||
based on it. */
|
||||
$.ajax({
|
||||
url: "index.json" + '?timestamp=' + $.asv.main_timestamp,
|
||||
dataType: "json",
|
||||
cache: true
|
||||
}).done(function (index) {
|
||||
main_json = index;
|
||||
$.asv.main_json = index;
|
||||
|
||||
/* Page title */
|
||||
var project_name = $("#project-name")[0];
|
||||
project_name.textContent = index.project;
|
||||
project_name.setAttribute("href", index.project_url);
|
||||
$("#project-name").textContent = index.project;
|
||||
document.title = "airspeed velocity of an unladen " + index.project;
|
||||
|
||||
$(window).on('hashchange', hashchange);
|
||||
|
||||
$('#graph-display').hide();
|
||||
$('#regressions-display').hide();
|
||||
$('#summarygrid-display').hide();
|
||||
$('#summarylist-display').hide();
|
||||
|
||||
hashchange();
|
||||
}).fail(function () {
|
||||
$.asv.ui.network_error();
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
/* Fetch the info.json */
|
||||
$.ajax({
|
||||
url: "info.json",
|
||||
dataType: "json",
|
||||
cache: false
|
||||
}).done(function (info) {
|
||||
main_timestamp = info['timestamp'];
|
||||
$.asv.main_timestamp = main_timestamp;
|
||||
init_index();
|
||||
}).fail(function () {
|
||||
$.asv.ui.network_error();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Set up $.asv
|
||||
*/
|
||||
|
||||
this.register_page = function(name, show_function) {
|
||||
loaded_pages[name] = show_function;
|
||||
}
|
||||
this.parse_hash_string = parse_hash_string;
|
||||
this.format_hash_string = format_hash_string;
|
||||
|
||||
this.filter_graph_data = filter_graph_data;
|
||||
this.filter_graph_data_idx = filter_graph_data_idx;
|
||||
this.convert_benchmark_param_value = convert_benchmark_param_value;
|
||||
this.param_selection_from_flat_idx = param_selection_from_flat_idx;
|
||||
this.graph_to_path = graph_to_path;
|
||||
this.load_graph_data = load_graph_data;
|
||||
this.get_commit_hash = get_commit_hash;
|
||||
this.get_revision = get_revision;
|
||||
|
||||
this.main_timestamp = main_timestamp; /* Updated after info.json loads */
|
||||
this.main_json = main_json; /* Updated after index.json loads */
|
||||
|
||||
this.format_date_yyyymmdd = format_date_yyyymmdd;
|
||||
this.format_date_yyyymmdd_hhmm = format_date_yyyymmdd_hhmm;
|
||||
this.pretty_unit = pretty_unit;
|
||||
this.time_units = time_units;
|
||||
this.mem_units = mem_units;
|
||||
|
||||
this.colors = colors;
|
||||
|
||||
$.asv = this;
|
||||
|
||||
|
||||
/*
|
||||
Launch it
|
||||
*/
|
||||
|
||||
init();
|
||||
});
|
231
docs/benchmarks/asv_ui.js
Normal file
231
docs/benchmarks/asv_ui.js
Normal file
|
@ -0,0 +1,231 @@
|
|||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
function make_panel(nav, heading) {
|
||||
var panel = $('<div class="panel panel-default"/>');
|
||||
nav.append(panel);
|
||||
var panel_header = $(
|
||||
'<div class="panel-heading">' + heading + '</div>');
|
||||
panel.append(panel_header);
|
||||
var panel_body = $('<div class="panel-body"/>');
|
||||
panel.append(panel_body);
|
||||
return panel_body;
|
||||
}
|
||||
|
||||
function make_value_selector_panel(nav, heading, values, setup_callback) {
|
||||
var panel_body = make_panel(nav, heading);
|
||||
var vertical = false;
|
||||
var buttons = $('<div class="btn-group" ' +
|
||||
'data-toggle="buttons"/>');
|
||||
|
||||
panel_body.append(buttons);
|
||||
|
||||
$.each(values, function (idx, value) {
|
||||
var button = $(
|
||||
'<a class="btn btn-default btn-xs active" role="button"/>');
|
||||
setup_callback(idx, value, button);
|
||||
buttons.append(button);
|
||||
});
|
||||
|
||||
return panel_body;
|
||||
}
|
||||
|
||||
function reflow_value_selector_panels(no_timeout) {
|
||||
$('.panel').each(function (i, panel_obj) {
|
||||
var panel = $(panel_obj);
|
||||
panel.find('.btn-group').each(function (i, buttons_obj) {
|
||||
var buttons = $(buttons_obj);
|
||||
var width = 0;
|
||||
|
||||
if (buttons.hasClass('reflow-done')) {
|
||||
/* already processed */
|
||||
return;
|
||||
}
|
||||
|
||||
$.each(buttons.children(), function(idx, value) {
|
||||
width += value.scrollWidth;
|
||||
});
|
||||
|
||||
var max_width = panel_obj.clientWidth;
|
||||
|
||||
if (width >= max_width) {
|
||||
buttons.addClass("btn-group-vertical");
|
||||
buttons.css("width", "100%");
|
||||
buttons.css("max-height", "20ex");
|
||||
buttons.css("overflow-y", "auto");
|
||||
}
|
||||
else {
|
||||
buttons.addClass("btn-group-justified");
|
||||
}
|
||||
|
||||
/* The widths can be zero if the UI is not fully layouted yet,
|
||||
so mark the adjustment complete only if this is not the case */
|
||||
if (width > 0 && max_width > 0) {
|
||||
buttons.addClass("reflow-done");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!no_timeout) {
|
||||
/* Call again asynchronously, in case the UI was not fully layouted yet */
|
||||
setTimeout(function() { $.asv.ui.reflow_value_selector_panels(true); }, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function network_error(ajax, status, error) {
|
||||
$("#error-message").text(
|
||||
"Error fetching content. " +
|
||||
"Perhaps web server has gone down.");
|
||||
$("#error").modal('show');
|
||||
}
|
||||
|
||||
function hover_graph(element, graph_url, benchmark_basename, parameter_idx, revisions) {
|
||||
/* Show the summary graph as a popup */
|
||||
var plot_div = $('<div/>');
|
||||
plot_div.css('width', '11.8em');
|
||||
plot_div.css('height', '7em');
|
||||
plot_div.css('border', '2px solid black');
|
||||
plot_div.css('background-color', 'white');
|
||||
|
||||
function update_plot() {
|
||||
var markings = [];
|
||||
|
||||
if (revisions) {
|
||||
$.each(revisions, function(i, revs) {
|
||||
var rev_a = revs[0];
|
||||
var rev_b = revs[1];
|
||||
|
||||
if (rev_a !== null) {
|
||||
markings.push({ color: '#d00', lineWidth: 2, xaxis: { from: rev_a, to: rev_a }});
|
||||
markings.push({ color: "rgba(255,0,0,0.1)", xaxis: { from: rev_a, to: rev_b }});
|
||||
}
|
||||
markings.push({ color: '#d00', lineWidth: 2, xaxis: { from: rev_b, to: rev_b }});
|
||||
});
|
||||
}
|
||||
|
||||
$.asv.load_graph_data(
|
||||
graph_url
|
||||
).done(function (data) {
|
||||
var params = $.asv.main_json.benchmarks[benchmark_basename].params;
|
||||
data = $.asv.filter_graph_data_idx(data, 0, parameter_idx, params);
|
||||
var options = {
|
||||
colors: ['#000'],
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2
|
||||
},
|
||||
shadowSize: 0
|
||||
},
|
||||
grid: {
|
||||
borderWidth: 1,
|
||||
margin: 0,
|
||||
labelMargin: 0,
|
||||
axisMargin: 0,
|
||||
minBorderMargin: 0,
|
||||
markings: markings,
|
||||
},
|
||||
xaxis: {
|
||||
ticks: [],
|
||||
},
|
||||
yaxis: {
|
||||
ticks: [],
|
||||
min: 0
|
||||
},
|
||||
legend: {
|
||||
show: false
|
||||
}
|
||||
};
|
||||
var plot = $.plot(plot_div, [{data: data}], options);
|
||||
}).fail(function () {
|
||||
// TODO: Handle failure
|
||||
});
|
||||
|
||||
return plot_div;
|
||||
}
|
||||
|
||||
element.popover({
|
||||
placement: 'left auto',
|
||||
trigger: 'hover',
|
||||
html: true,
|
||||
delay: 50,
|
||||
content: $('<div/>').append(plot_div)
|
||||
});
|
||||
|
||||
element.on('show.bs.popover', update_plot);
|
||||
}
|
||||
|
||||
function hover_summary_graph(element, benchmark_basename) {
|
||||
/* Show the summary graph as a popup */
|
||||
var plot_div = $('<div/>');
|
||||
plot_div.css('width', '11.8em');
|
||||
plot_div.css('height', '7em');
|
||||
plot_div.css('border', '2px solid black');
|
||||
plot_div.css('background-color', 'white');
|
||||
|
||||
function update_plot() {
|
||||
var markings = [];
|
||||
|
||||
$.asv.load_graph_data(
|
||||
'graphs/summary/' + benchmark_basename + '.json'
|
||||
).done(function (data) {
|
||||
var options = {
|
||||
colors: $.asv.colors,
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2
|
||||
},
|
||||
shadowSize: 0
|
||||
},
|
||||
grid: {
|
||||
borderWidth: 1,
|
||||
margin: 0,
|
||||
labelMargin: 0,
|
||||
axisMargin: 0,
|
||||
minBorderMargin: 0,
|
||||
markings: markings,
|
||||
},
|
||||
xaxis: {
|
||||
ticks: [],
|
||||
},
|
||||
yaxis: {
|
||||
ticks: [],
|
||||
min: 0
|
||||
},
|
||||
legend: {
|
||||
show: false
|
||||
}
|
||||
};
|
||||
var plot = $.plot(plot_div, [{data: data}], options);
|
||||
}).fail(function () {
|
||||
// TODO: Handle failure
|
||||
});
|
||||
|
||||
return plot_div;
|
||||
}
|
||||
|
||||
element.popover({
|
||||
placement: 'left auto',
|
||||
trigger: 'hover',
|
||||
html: true,
|
||||
delay: 50,
|
||||
content: $('<div/>').append(plot_div)
|
||||
});
|
||||
|
||||
element.on('show.bs.popover', update_plot);
|
||||
}
|
||||
|
||||
/*
|
||||
Set up $.asv.ui
|
||||
*/
|
||||
|
||||
this.network_error = network_error;
|
||||
this.make_panel = make_panel;
|
||||
this.make_value_selector_panel = make_value_selector_panel;
|
||||
this.reflow_value_selector_panels = reflow_value_selector_panels;
|
||||
this.hover_graph = hover_graph;
|
||||
this.hover_summary_graph = hover_summary_graph;
|
||||
|
||||
$.asv.ui = this;
|
||||
});
|
23
docs/benchmarks/error.html
Normal file
23
docs/benchmarks/error.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>airspeed velocity error</title>
|
||||
<link rel="shortcut icon" href="swallow.ico"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
<img src="swallow.png" width="22" height="22" alt="swallow"></img>
|
||||
Can not determine continental origin of swallow.
|
||||
</h1>
|
||||
|
||||
<h3>
|
||||
One or more external (JavaScript) dependencies of airspeed velocity failed to load.
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
Make sure you have an active internet connection and enable 3rd-party scripts
|
||||
in your browser the first time you load airspeed velocity.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
1427
docs/benchmarks/graphdisplay.js
Normal file
1427
docs/benchmarks/graphdisplay.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1 @@
|
|||
[[1662, [52920320.0, 54566912.0]], [1672, [52350976.0, 54599680.0]], [1687, [52109312.0, 54779904.0]], [1691, [52899840.0, 54730752.0]], [1709, [52936704.0, 55009280.0]], [1726, [52379648.0, 54992896.0]], [1766, [53084160.0, 55382016.0]], [1770, [53047296.0, 55373824.0]], [1776, [52490240.0, 55361536.0]], [1801, [53153792.0, 55410688.0]], [1937, [52957184.0, 55177216.0]], [1960, [52932608.0, 55693312.0]], [1996, [53096448.0, 55484416.0]], [2029, [52715520.0, 56090624.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [53800960.0, 54734848.0]], [1672, [52289536.0, 55099392.0]], [1687, [52142080.0, 55255040.0]], [1691, [53796864.0, 55238656.0]], [1709, [53768192.0, 55455744.0]], [1726, [51998720.0, 55451648.0]], [1766, [53739520.0, 55812096.0]], [1770, [53948416.0, 55824384.0]], [1776, [52097024.0, 55791616.0]], [1801, [53919744.0, 55799808.0]], [1937, [52822016.0, 56242176.0]], [1960, [53063680.0, 56180736.0]], [1996, [53018624.0, 56389632.0]], [2029, [52736000.0, 56791040.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [44191744.0, 44191744.0]], [1672, [44056576.0, 44048384.0]], [1687, [44191744.0, 44310528.0]], [1691, [44183552.0, 44175360.0]], [1709, [44191744.0, 44314624.0]], [1726, [44195840.0, 44314624.0]], [1766, [44322816.0, 44314624.0]], [1770, [44326912.0, 44322816.0]], [1776, [44183552.0, 44306432.0]], [1801, [44195840.0, 44453888.0]], [1937, [44756992.0, 44744704.0]], [1960, [44716032.0, 44834816.0]], [1996, [44716032.0, 44969984.0]], [2029, [44871680.0, 44912640.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [44195840.0, 44187648.0]], [1672, [44060672.0, 43917312.0]], [1687, [44105728.0, 44310528.0]], [1691, [44187648.0, 44183552.0]], [1709, [44191744.0, 44437504.0]], [1726, [44322816.0, 44314624.0]], [1766, [44322816.0, 44310528.0]], [1770, [44101632.0, 44310528.0]], [1776, [44314624.0, 44437504.0]], [1801, [44191744.0, 44453888.0]], [1937, [44527616.0, 44744704.0]], [1960, [44716032.0, 44838912.0]], [1996, [44724224.0, 44969984.0]], [2029, [44617728.0, 44986368.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.06960565700001098, 0.25608221199996706]], [1672, [0.07114163800000028, 0.26389872900000455]], [1687, [0.06910802600003763, 0.25746033199999374]], [1691, [0.07048037500001669, 0.2598985070000026]], [1709, [0.07402671400001282, 0.26584690599997884]], [1726, [0.07297276199997782, 0.2569234329999972]], [1766, [0.07308550800001967, 0.26274096600002395]], [1770, [0.0749189080000292, 0.26436952000000247]], [1776, [0.07303507899999317, 0.2628890319999755]], [1801, [0.07360306399999672, 0.2678246009999725]], [1937, [0.07941284200001064, 0.26779402600004687]], [1960, [0.08026317200000221, 0.26819844099998136]], [1996, [0.0814841690000776, 0.28364495499999975]], [2029, [0.08105427499998541, 0.29477426600001877]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.03327357099999517, 0.1421111020000012]], [1672, [0.033918617999972867, 0.14395761299999776]], [1687, [0.03317536700001256, 0.14245594600001255]], [1691, [0.034316510999985894, 0.1444248799999741]], [1709, [0.03742426899998463, 0.14901454800002512]], [1726, [0.03658580800001232, 0.1459621130000528]], [1766, [0.03723830100000214, 0.15196534300002895]], [1770, [0.03752758399997447, 0.15356457899997622]], [1776, [0.03678920999999491, 0.14955294699998944]], [1801, [0.037022983000014165, 0.15138703899998518]], [1937, [0.043317416999911984, 0.15457556900003055]], [1960, [0.04349111400000538, 0.15453611999998884]], [1996, [0.04362213900003553, 0.16551773399999092]], [2029, [0.043648402000002307, 0.17461173199995983]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.0035443229999998493, 0.00467639600003622]], [1672, [0.0036137869999777195, 0.004807943000002979]], [1687, [0.0035223549999727766, 0.004706463999980315]], [1691, [0.00364059099999281, 0.004926952999994683]], [1709, [0.003602947999979733, 0.004853936999950292]], [1726, [0.0035008030000085455, 0.004695608999981005]], [1766, [0.003566315000000486, 0.004791812000007667]], [1770, [0.0036766670000361046, 0.004929383999979109]], [1776, [0.0035613420000117912, 0.004760385999986738]], [1801, [0.003639607999986083, 0.004848561000017071]], [1937, [0.0036632869999948525, 0.00493345400002454]], [1960, [0.0036145729999930154, 0.004811176000004025]], [1996, [0.00375721499995052, 0.0049729269999261305]], [2029, [0.0037106409999978496, 0.004899473999955717]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.00010400499999718704, 0.0005328339999977061]], [1672, [0.00010086800000408402, 0.0005549249999887707]], [1687, [9.818199998790078e-05, 0.0005511469999817109]], [1691, [0.0001005780000014056, 0.0005555879999974422]], [1709, [0.00012266099997759738, 0.0005711430000019391]], [1726, [0.00011641800000461444, 0.0005489540000098714]], [1766, [0.00011609900002440554, 0.0005779780000239043]], [1770, [0.0001176700000087294, 0.0005864990000077341]], [1776, [0.00011622699999236374, 0.0005842630000074678]], [1801, [0.00011665800002447213, 0.000582710000003317]], [1937, [0.00012153600005149201, 0.0005999570000199128]], [1960, [0.00012332000000014887, 0.0005915369999911491]], [1996, [0.00012686900004155177, 0.0006182140000419167]], [2029, [0.00012706900002967814, 0.0006100459999629493]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.21775109000003567, 0.21398552899995593]], [1672, [0.22476057199997967, 0.22048105400000395]], [1687, [0.21809406599999193, 0.2131839880000257]], [1691, [0.22356123500000535, 0.22167734499998915]], [1709, [0.22133603999998286, 0.21805855799999563]], [1726, [0.2166100470000174, 0.21420494400001644]], [1766, [0.22339861599999722, 0.22020213500002228]], [1770, [0.22985272800002576, 0.22544496099999378]], [1776, [0.22073260000001937, 0.2182690520000392]], [1801, [0.224061646999985, 0.2246476189999953]], [1937, [0.22743783699991127, 0.226070988999993]], [1960, [0.2252378419999843, 0.2247263650000093]], [1996, [0.23076480500003527, 0.23163660399995933]], [2029, [0.22799248500001568, 0.22723498599998493]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.19832900800003017], [1672, 0.20217585500000723], [1687, 0.19726691500000015], [1691, 0.20350580199999513], [1709, 0.19950735400001918], [1726, 0.19625152499997967], [1766, 0.20073733000003813], [1770, 0.20376683500001036], [1776, 0.19919827600000417], [1801, 0.2053688209999791], [1937, 0.2063091950000171], [1960, 0.20468290799999522], [1996, 0.21042045099989082], [2029, 0.2056691309999792]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [54439936.0, 53968896.0]], [1672, [54616064.0, 54140928.0]], [1687, [54767616.0, 54296576.0]], [1691, [54743040.0, 54087680.0]], [1709, [55001088.0, 54312960.0]], [1726, [54992896.0, 54345728.0]], [1766, [55373824.0, 54894592.0]], [1770, [55246848.0, 54898688.0]], [1776, [55357440.0, 54874112.0]], [1801, [55382016.0, 54882304.0]], [1937, [55222272.0, 54722560.0]], [1960, [55263232.0, 54693888.0]], [1996, [55476224.0, 54968320.0]], [2029, [56090624.0, 55582720.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [54968320.0, 54792192.0]], [1672, [54849536.0, 54841344.0]], [1687, [55271424.0, 55304192.0]], [1691, [54984704.0, 54964224.0]], [1709, [55439360.0, 55369728.0]], [1726, [55455744.0, 55177216.0]], [1766, [55545856.0, 55631872.0]], [1770, [55812096.0, 55611392.0]], [1776, [55640064.0, 55631872.0]], [1801, [55812096.0, 55902208.0]], [1937, [56008704.0, 56143872.0]], [1960, [55783424.0, 56160256.0]], [1996, [56352768.0, 56516608.0]], [2029, [56786944.0, 56778752.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [44187648.0, 44183552.0]], [1672, [44048384.0, 44048384.0]], [1687, [44314624.0, 44310528.0]], [1691, [44179456.0, 44175360.0]], [1709, [44314624.0, 44310528.0]], [1726, [44314624.0, 44314624.0]], [1766, [44318720.0, 44314624.0]], [1770, [44322816.0, 44314624.0]], [1776, [44306432.0, 44240896.0]], [1801, [44453888.0, 44453888.0]], [1937, [44744704.0, 44744704.0]], [1960, [44838912.0, 44838912.0]], [1996, [44969984.0, 44969984.0]], [2029, [44843008.0, 44851200.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [44187648.0, 44187648.0]], [1672, [44052480.0, 44052480.0]], [1687, [44314624.0, 44310528.0]], [1691, [44179456.0, 44179456.0]], [1709, [44310528.0, 44314624.0]], [1726, [44314624.0, 44314624.0]], [1766, [44310528.0, 44314624.0]], [1770, [44314624.0, 44318720.0]], [1776, [44437504.0, 44437504.0]], [1801, [44449792.0, 44449792.0]], [1937, [44744704.0, 44744704.0]], [1960, [44965888.0, 44834816.0]], [1996, [44974080.0, 44974080.0]], [2029, [44982272.0, 44986368.0]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.2574955810000006, 0.2591010970000127]], [1672, [0.2600247560000071, 0.26185358800000813]], [1687, [0.2567828300000201, 0.2602957870000182]], [1691, [0.259077934000004, 0.2619792840000059]], [1709, [0.2646600410000133, 0.2676605120000204]], [1726, [0.2570519909999689, 0.2606809000000112]], [1766, [0.262679922000018, 0.2686107789999994]], [1770, [0.265977821000007, 0.26914772099999595]], [1776, [0.2626667089999728, 0.2663110299999971]], [1801, [0.2658582709999848, 0.2712929850000023]], [1937, [0.2675778039999841, 0.2724974679999832]], [1960, [0.26819597400000816, 0.2740507329999957]], [1996, [0.2794132599999557, 0.28440619299999526]], [2029, [0.2920349000000044, 0.2976166970000236]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.14273938200000202, 0.1464969190000147]], [1672, [0.14515931700000806, 0.14909453600000688]], [1687, [0.1423055980000072, 0.14642362500001127]], [1691, [0.1436571560000175, 0.14915657599999577]], [1709, [0.14860135300000366, 0.15305296299999327]], [1726, [0.14520097999997006, 0.14991973799999414]], [1766, [0.15071133700001837, 0.15540660900001058]], [1770, [0.15150350199996865, 0.1558047899999906]], [1776, [0.14876902899999322, 0.15549233400000162]], [1801, [0.15248822700002052, 0.15465820200000735]], [1937, [0.15459265900005903, 0.15926110200007315]], [1960, [0.15396625699997912, 0.16023626799997714]], [1996, [0.16650312799993117, 0.17177308600003016]], [2029, [0.17414895399997476, 0.178393189000019]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.004720848000005162, 0.004705489000002672]], [1672, [0.004856270999994194, 0.00490694800001279]], [1687, [0.00473016699999107, 0.004734037999980956]], [1691, [0.004871503999993365, 0.0048899079999955575]], [1709, [0.0048215560000244295, 0.004858458999990489]], [1726, [0.004671787999996013, 0.004672599999992144]], [1766, [0.00478528000002143, 0.0047485900000197034]], [1770, [0.004901490999998259, 0.004895917999988342]], [1776, [0.00480728600001612, 0.00472804499997892]], [1801, [0.004847185000016907, 0.004857667999999649]], [1937, [0.004923484000073586, 0.004925836999973399]], [1960, [0.004825538000005736, 0.0047952310000027865]], [1996, [0.005049280000093859, 0.004947880000145233]], [2029, [0.004897051999989799, 0.004863266000029398]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.0005377129999999397, 0.0005395769999836375]], [1672, [0.000547750000009728, 0.0005677989999810507]], [1687, [0.0005471899999918151, 0.0005447550000212686]], [1691, [0.0005559489999882317, 0.0005480739999939033]], [1709, [0.0005736080000247057, 0.0005720849999875099]], [1726, [0.000542692999999872, 0.0005430530000012368]], [1766, [0.0005853119999983392, 0.000582014999963576]], [1770, [0.0005929909999622396, 0.000583071999983531]], [1776, [0.0005810670000130358, 0.000576186999978745]], [1801, [0.0005717709999828458, 0.0005785939999896073]], [1937, [0.0005969709999362749, 0.0005864510000037626]], [1960, [0.0005953940000154034, 0.0005933700000468889]], [1996, [0.0006160310000495883, 0.0006166809999967882]], [2029, [0.0006159270000125616, 0.0006080119999865019]]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, [0.21402431699999624, 0.21364062999998623]], [1672, [0.2221746719999942, 0.2222580240000127]], [1687, [0.2142312400000037, 0.21397752699999728]], [1691, [0.22129613300000983, 0.21942976399998315]], [1709, [0.2199001029999863, 0.22046102699999892]], [1726, [0.2147675530000015, 0.21506381099999317]], [1766, [0.22056839900000114, 0.21916191200000412]], [1770, [0.22394285699999728, 0.22330144500000415]], [1776, [0.21867883100003382, 0.21859779499999377]], [1801, [0.22378945699995256, 0.22211803700002974]], [1937, [0.22545313400001987, 0.22602228000005198]], [1960, [0.22564571399999522, 0.22598634599995648]], [1996, [0.2295973340000046, 0.23030742100002044]], [2029, [0.22777395400004252, 0.2292747939999913]]]
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
[[1662, 53737309.613078326], [1672, 53463506.59363525], [1687, 53427924.42970294], [1691, 53807508.99158667], [1709, 53963042.655257314], [1726, 53670369.245800875], [1766, 54220916.6140389], [1770, 54198077.75539557], [1776, 53906774.26269022], [1801, 54270509.344660625], [1937, 54055804.31664803], [1960, 54295416.494559616], [1996, 54277301.04707094], [2029, 54376892.25474807]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 54265895.0709751], [1672, 53676080.7209516], [1687, 53675997.57883592], [1691, 54512993.537089705], [1709, 54605449.27839023], [1726, 53697436.790693834], [1766, 54766004.5031032], [1770, 54878384.55144014], [1776, 53912680.86221259], [1801, 54851721.60114168], [1937, 54505276.07990639], [1960, 54599968.83944605], [1996, 54678155.56971878], [2029, 54725974.50425164]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 44191743.99999999], [1672, 44052479.80957694], [1687, 44251096.14326895], [1691, 44179455.81012423], [1709, 44253141.3491094], [1726, 44255192.14695785], [1766, 44318719.81072088], [1770, 44324863.95268679], [1776, 44244949.34121254], [1801, 44324676.21343578], [1937, 44750847.578234404], [1960, 44775384.609963], [1996, 44842828.229087956], [2029, 44892155.328466915]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 44191743.81017703], [1672, 43988933.59873213], [1687, 44208009.40445502], [1691, 44185599.95253766], [1709, 44314453.63272547], [1726, 44318719.81072088], [1766, 44316671.57410231], [1770, 44205956.60747199], [1776, 44376021.4672124], [1801, 44322622.19567646], [1937, 44636028.0238471], [1960, 44777429.84849827], [1996, 44846935.655543014], [2029, 44801668.84315699]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.13350944016163727], [1672, 0.1370189324406613], [1687, 0.13338881256624893], [1691, 0.13534306127506], [1709, 0.14028461383291016], [1726, 0.1369248426273554], [1766, 0.13857329097819557], [1770, 0.14073477092350728], [1776, 0.1385645020210802], [1801, 0.14040196312080028], [1937, 0.14582964264952603], [1960, 0.14671897491501892], [1996, 0.15202819951982394], [2029, 0.15457268328939747]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.0687644082522681], [1672, 0.06987734456556612], [1687, 0.06874611472573841], [1691, 0.07039998567606925], [1709, 0.07467771106069107], [1726, 0.07307627413528986], [1766, 0.0752258677863117], [1770, 0.07591381717343901], [1776, 0.0741750279629251], [1801, 0.07486521068773488], [1937, 0.08182795598310513], [1960, 0.08198138820511656], [1996, 0.08497198126158123], [2029, 0.08730133488241124]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.004071198582731586], [1672, 0.004168318834979474], [1687, 0.004071589002161507], [1691, 0.004235212007582172], [1709, 0.004181923314217816], [1726, 0.004054429932062044], [1766, 0.004133897799028137], [1770, 0.004257194320585938], [1776, 0.004117446125697445], [1801, 0.004200816754404154], [1937, 0.004251194879485355], [1960, 0.0041701734817425696], [1996, 0.004322540447211732], [2029, 0.004263823296369016]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.00023540900613243872], [1672, 0.0002365886195511814], [1687, 0.0002326213978668684], [1691, 0.0002363893607261623], [1709, 0.0002646827752432008], [1726, 0.00025280056719810247], [1766, 0.00025904182642747317], [1770, 0.0002627038966898471], [1776, 0.00026058997620285855], [1801, 0.000260725493948419], [1937, 0.0002700303204925571], [1960, 0.00027008950893915996], [1996, 0.0002800574798090668], [2029, 0.000278420428825539]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.21586009863792485], [1672, 0.22261052942796597], [1687, 0.21562505130206716], [1691, 0.2226172972159168], [1709, 0.21969118716012626], [1726, 0.21540413874268913], [1766, 0.2217946171557135], [1770, 0.22763817627917332], [1776, 0.21949736979633283], [1801, 0.22435444169386096], [1937, 0.22675338309844276], [1960, 0.22498195815021013], [1996, 0.23120029358312028], [2029, 0.22761342037999505]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.19832900800003017], [1672, 0.20217585500000723], [1687, 0.19726691500000015], [1691, 0.20350580199999513], [1709, 0.19950735400001918], [1726, 0.19625152499997967], [1766, 0.20073733000003813], [1770, 0.20376683500001036], [1776, 0.19919827600000417], [1801, 0.2053688209999791], [1937, 0.2063091950000171], [1960, 0.20468290799999522], [1996, 0.21042045099989082], [2029, 0.2056691309999792]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 54203904.32644733], [1672, 54377977.05567385], [1687, 54531587.401090905], [1691, 54414373.37457081], [1709, 54655941.05401974], [1726, 54668354.35558938], [1766, 55133687.30603648], [1770, 55072492.873806104], [1776, 55115246.19008138], [1801, 55131593.83007953], [1937, 54971848.18483294], [1960, 54977822.99733244], [1996, 55221688.06930552], [2029, 55836094.494666085]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 54880185.34368702], [1672, 54845439.84705003], [1687, 55287805.57238104], [1691, 54974463.04630629], [1709, 55404533.06087942], [1726, 55316304.695168346], [1766, 55588847.36277981], [1770, 55711653.6193069], [1776, 55635967.849223286], [1801, 55857133.82825839], [1937, 56076247.273349956], [1960, 55971522.87008585], [1996, 56434628.542863145], [2029, 56782847.85226863]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 44185599.95253766], [1672, 44048383.99999999], [1687, 44312575.95267366], [1691, 44177407.95252886], [1709, 44312575.95267366], [1726, 44314624.0], [1766, 44316671.95267803], [1770, 44318719.81072088], [1776, 44273651.87380721], [1801, 44453888.0], [1937, 44744704.0], [1960, 44838912.00000001], [1996, 44969983.99999999], [2029, 44847103.812950954]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 44187648.0], [1672, 44052479.99999999], [1687, 44312575.95267366], [1691, 44179455.99999999], [1709, 44312575.95267366], [1726, 44314624.0], [1766, 44312575.95267366], [1770, 44316671.95267803], [1776, 44437504.0], [1801, 44449792.0], [1937, 44744704.0], [1960, 44900304.17220587], [1996, 44974080.0], [2029, 44984319.953380376]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.2582970915627115], [1672, 0.2609375697890752], [1687, 0.2585333418012986], [1691, 0.2605245701455466], [1709, 0.26615604836262874], [1726, 0.25886008645727265], [1766, 0.2656287982807661], [1770, 0.2675580766089799], [1776, 0.2644825926606367], [1801, 0.26856188100049755], [1937, 0.2700264321932048], [1960, 0.2711075492537049], [1996, 0.28189867248766043], [2029, 0.29481258851469266]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.144605946222714], [1672, 0.14711376894836906], [1687, 0.14434992731884352], [1691, 0.14638104217028877], [1709, 0.1508107336447194], [1726, 0.14754149544768042], [1766, 0.15304096778650703], [1770, 0.1536390943522132], [1776, 0.15209353551720362], [1801, 0.15356938175949056], [1937, 0.15690951925702573], [1960, 0.15706997937098616], [1996, 0.16911758076913888], [2029, 0.17625829701058932]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.004713162243622524], [1672, 0.004881543738505435], [1687, 0.004732102104161917], [1691, 0.00488069732533968], [1709, 0.004839972328668506], [1726, 0.004672193982353972], [1766, 0.004766899700580667], [1770, 0.004898703707479391], [1776, 0.004767500868992566], [1801, 0.004852423669122516], [1937, 0.004924660359490744], [1960, 0.004810360631940079], [1996, 0.004998322871483767], [2029, 0.004880129761791827]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.0005386441936864901], [1672, 0.0005576844109755481], [1687, 0.0005459711425132094], [1691, 0.0005519974567116778], [1709, 0.0005728459938648165], [1726, 0.0005428729701593198], [1766, 0.0005836611719634209], [1770, 0.0005880105852110292], [1776, 0.0005786218553806627], [1801, 0.0005751723828193878], [1937, 0.0005916876201898046], [1960, 0.000594381138510516], [1996, 0.0006163559143381376], [2029, 0.0006119567036345985]]
|
|
@ -0,0 +1 @@
|
|||
[[1662, 0.21383238744211777], [1672, 0.22221634409189991], [1687, 0.21410434591886193], [1691, 0.2203609725843055], [1709, 0.22018038637622225], [1726, 0.2149156309515977], [1766, 0.2198640308272821], [1770, 0.22362192103085216], [1776, 0.21863830924562072], [1801, 0.22295218072522197], [1937, 0.22573752762853083], [1960, 0.22581596577171012], [1996, 0.22995210340856065], [2029, 0.2285231418957897]]
|
161
docs/benchmarks/index.html
Normal file
161
docs/benchmarks/index.html
Normal file
|
@ -0,0 +1,161 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>airspeed velocity</title>
|
||||
<script type="text/javascript">
|
||||
function js_load_failure() {
|
||||
window.location = "error.html";
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js" integrity="sha512-eO1AKNIv7KSFl5n81oHCKnYLMi8UV4wWD1TcLYKNTssoECDuiGhoRsQkdiZkl8VUjoms2SeJY7zTSw5noGSqbQ==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.time.min.js" integrity="sha512-lcRowrkiQvFli9HkuJ2Yr58iEwAtzhFNJ1Galsko4SJDhcZfUub8UxGlMQIsMvARiTqx2pm7g6COxJozihOixA==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.selection.min.js" integrity="sha512-3EUG0t3qfbLaGN3FXO86i+57nvxHOXvIb/xMSKRrCuX/HXdn1bkbqwAeLd6U1PDmuEB2cnKhfM+SGLAVQbyjWQ==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.categories.min.js" integrity="sha512-x4QGSZkQ57pNuICMFFevIhDer5NVB5eJCRmENlCdJukMs8xWFH8OHfzWQVSkl9VQ4+4upPPTkHSAewR6KNMjGA==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script language="javascript" type="text/javascript" src="jquery.flot.axislabels.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/flot-orderbars@1.0.0/js/jquery.flot.orderBars.js" integrity="sha256-OXNbT0b5b/TgglckAfR8VaJ2ezZv0dHoIeRKjYMKEr8=" crossorigin="anonymous" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/stupidtable/1.0.1/stupidtable.min.js" integrity="sha512-GM3Ds3dUrgkpKVXc+4RxKbQDoeTemdlzXxn5d/QCOJT6EFdEufu1UTVBpIFDLd6YjIhSThNe+zpo1mwqzNq4GQ==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.19.0/js/md5.min.js" integrity="sha512-8pbzenDolL1l5OPSsoURCx9TEdMFTaeFipASVrMYKhuYtly+k3tcsQYliOEKTmuB1t7yuzAiVo+yd7SJz+ijFQ==" crossorigin="anonymous" referrerpolicy="no-referrer" onerror="js_load_failure()"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.1.1/dist/js/bootstrap.min.js" integrity="sha256-iY0FoX8s/FEg3c26R6iFw3jAtGbzDwcA5QJ1fiS0A6E=" crossorigin="anonymous" onerror="js_load_failure()"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.1.1/dist/css/bootstrap.min.css" integrity="sha256-6VA0SGkrc43SYPvX98q/LhHwm2APqX5us6Vuulsafps=" crossorigin="anonymous">
|
||||
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="asv.js">
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="asv_ui.js">
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="summarygrid.js">
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="summarylist.js">
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="graphdisplay.js">
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript"
|
||||
src="regressions.js">
|
||||
</script>
|
||||
<link href="asv.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="regressions.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="summarylist.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="shortcut icon" href="swallow.ico"/>
|
||||
<link rel="alternate" type="application/atom+xml" title="Regressions" href="regressions.xml"/>
|
||||
</head>
|
||||
<body>
|
||||
<nav id="nav" class="navbar navbar-left navbar-default navbar-fixed-top" role="navigation">
|
||||
<ul class="nav navbar-nav navbar-left">
|
||||
<li>
|
||||
<p class="navbar-text">
|
||||
<a href="http://github.com/airspeed-velocity/asv/" class="navbar-link" target="_blank"><img src="swallow.png" width="22" height="22" alt="swallow"></img>airspeed velocity</a>
|
||||
of an unladen
|
||||
<a id="project-name" href="#" class="navbar-link" target="_blank">project</a>
|
||||
</p>
|
||||
</li>
|
||||
<li id="nav-li-" class="active"><a href="#/">Benchmark grid</a></li>
|
||||
<li id="nav-li-summarylist"><a href="#/summarylist">Benchmark list</a></li>
|
||||
<li id="nav-li-regressions"><a href="#/regressions">Regressions</a></li>
|
||||
<li id="nav-li-graphdisplay">
|
||||
<span class="navbar-brand" id="title">
|
||||
benchmark
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div id="summarygrid-display" style="position: absolute; left: 0; top: 55px; width: 100%; height: 100%">
|
||||
</div>
|
||||
<div id="summarylist-display" style="width: 100%; height: 100%">
|
||||
<div id="summarylist-navigation" class="asv-navigation" style="position: absolute; left: 0; top: 55px; bottom: 0; width: 200px; overflow-y: scroll">
|
||||
</div>
|
||||
<div id="summarylist-body" style="position: absolute; left: 200px; top: 55px; bottom: 0px; right: 0px; overflow-y: scroll;">
|
||||
</div>
|
||||
</div>
|
||||
<div id="graph-display" style="width: 100%; height: 100%;">
|
||||
<div id="graphdisplay-navigation" class="asv-navigation" style="position: absolute; left: 0; top: 55px; bottom: 0; width: 200px; overflow-y: scroll">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
commits
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<input id="range" type="text" class="form-control" size="24" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
plot settings
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="btn-group-vertical" style="width: 100%" data-toggle="buttons">
|
||||
<a id="log-scale" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Use a logarithmic scale on the y-axis">
|
||||
log scale
|
||||
</a>
|
||||
<a id="zoom-y-axis" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Zoom y axis to the range of the data, rather than down to zero.">
|
||||
zoom <i>y</i> axis
|
||||
</a>
|
||||
<a id="reference" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Select a reference point">
|
||||
reference
|
||||
</a>
|
||||
<a id="even-spacing" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Space commits evenly, rather than by revision, along the x-axis">
|
||||
even commit spacing
|
||||
</a>
|
||||
<a id="date-scale" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Space commits by commit date along the x-axis">
|
||||
date scale
|
||||
</a>
|
||||
<a id="show-legend" class="btn btn-default btn-xs" role="button"
|
||||
data-toggle="tooltip" data-placement="right"
|
||||
title="Show legend in the graph">
|
||||
legend
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="position: absolute; left: 220px; top: 60px; bottom: 10px; right: 20px;">
|
||||
<div id="graph">
|
||||
<div style="position: absolute; top: 48px; left: 0; right: 0; bottom: 100px;">
|
||||
<div id="main-graph" style="min-height: 100px; width: 100%; height: 100%"></div>
|
||||
</div>
|
||||
<div style="position: absolute; height: 100px; left: 0; right: 0; bottom: 0; padding-top: 24px">
|
||||
<div id="overview" style="min-height: 100px; width: 100%; height: 100%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="regressions-display" style="position: absolute; left: 0; top: 55px; width: 100%; height: 100%">
|
||||
<div id="regressions-body">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- A modal dialog box for displaying error messages -->
|
||||
<div class="modal fade" id="error" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title alert alert-danger" id="myModalLabel">Error</h4>
|
||||
</div>
|
||||
<div class="modal-body" id="error-message">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
1
docs/benchmarks/index.json
Normal file
1
docs/benchmarks/index.json
Normal file
File diff suppressed because one or more lines are too long
4
docs/benchmarks/info.json
Normal file
4
docs/benchmarks/info.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"asv-version": "0.6.4",
|
||||
"timestamp": 1753049912703
|
||||
}
|
140
docs/benchmarks/jquery.flot.axislabels.js
Normal file
140
docs/benchmarks/jquery.flot.axislabels.js
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
CAxis Labels Plugin for flot. :P
|
||||
Copyright (c) 2010 Xuan Luo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
(function ($) {
|
||||
var options = { };
|
||||
|
||||
function init(plot) {
|
||||
// This is kind of a hack. There are no hooks in Flot between
|
||||
// the creation and measuring of the ticks (setTicks, measureTickLabels
|
||||
// in setupGrid() ) and the drawing of the ticks and plot box
|
||||
// (insertAxisLabels in setupGrid() ).
|
||||
//
|
||||
// Therefore, we use a trick where we run the draw routine twice:
|
||||
// the first time to get the tick measurements, so that we can change
|
||||
// them, and then have it draw it again.
|
||||
var secondPass = false;
|
||||
plot.hooks.draw.push(function (plot, ctx) {
|
||||
if (!secondPass) {
|
||||
// MEASURE AND SET OPTIONS
|
||||
$.each(plot.getAxes(), function(axisName, axis) {
|
||||
var opts = axis.options // Flot 0.7
|
||||
|| plot.getOptions()[axisName]; // Flot 0.6
|
||||
if (!opts || !opts.axisLabel)
|
||||
return;
|
||||
|
||||
var w, h;
|
||||
if (opts.axisLabelUseCanvas != false)
|
||||
opts.axisLabelUseCanvas = true;
|
||||
|
||||
if (opts.axisLabelUseCanvas) {
|
||||
// canvas text
|
||||
if (!opts.axisLabelFontSizePixels)
|
||||
opts.axisLabelFontSizePixels = 14;
|
||||
if (!opts.axisLabelFontFamily)
|
||||
opts.axisLabelFontFamily = 'sans-serif';
|
||||
// since we currently always display x as horiz.
|
||||
// and y as vertical, we only care about the height
|
||||
w = opts.axisLabelFontSizePixels;
|
||||
h = opts.axisLabelFontSizePixels;
|
||||
|
||||
} else {
|
||||
// HTML text
|
||||
var elem = $('<div class="axisLabels" style="position:absolute;">' + opts.axisLabel + '</div>');
|
||||
plot.getPlaceholder().append(elem);
|
||||
w = elem.outerWidth(true);
|
||||
h = elem.outerHeight(true);
|
||||
elem.remove();
|
||||
}
|
||||
|
||||
if (axisName.charAt(0) == 'x')
|
||||
axis.labelHeight += h;
|
||||
else
|
||||
axis.labelWidth += w;
|
||||
opts.labelHeight = axis.labelHeight;
|
||||
opts.labelWidth = axis.labelWidth;
|
||||
});
|
||||
// re-draw with new label widths and heights
|
||||
secondPass = true;
|
||||
plot.setupGrid();
|
||||
plot.draw();
|
||||
|
||||
|
||||
} else {
|
||||
// DRAW
|
||||
$.each(plot.getAxes(), function(axisName, axis) {
|
||||
var opts = axis.options // Flot 0.7
|
||||
|| plot.getOptions()[axisName]; // Flot 0.6
|
||||
if (!opts || !opts.axisLabel)
|
||||
return;
|
||||
|
||||
if (opts.axisLabelUseCanvas) {
|
||||
// canvas text
|
||||
var ctx = plot.getCanvas().getContext('2d');
|
||||
ctx.save();
|
||||
ctx.font = opts.axisLabelFontSizePixels + 'px ' +
|
||||
opts.axisLabelFontFamily;
|
||||
var width = ctx.measureText(opts.axisLabel).width;
|
||||
var height = opts.axisLabelFontSizePixels;
|
||||
var x, y;
|
||||
if (axisName.charAt(0) == 'x') {
|
||||
x = plot.getPlotOffset().left + plot.width()/2 - width/2;
|
||||
y = plot.getCanvas().height;
|
||||
} else {
|
||||
x = height * 0.72;
|
||||
y = plot.getPlotOffset().top + plot.height()/2 - width/2;
|
||||
}
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate((axisName.charAt(0) == 'x') ? 0 : -Math.PI/2);
|
||||
ctx.fillText(opts.axisLabel, 0, 0);
|
||||
ctx.restore();
|
||||
|
||||
} else {
|
||||
// HTML text
|
||||
plot.getPlaceholder().find('#' + axisName + 'Label').remove();
|
||||
var elem = $('<div id="' + axisName + 'Label" " class="axisLabels" style="position:absolute;">' + opts.axisLabel + '</div>');
|
||||
if (axisName.charAt(0) == 'x') {
|
||||
elem.css('left', plot.getPlotOffset().left + plot.width()/2 - elem.outerWidth()/2 + 'px');
|
||||
elem.css('bottom', '0px');
|
||||
} else {
|
||||
elem.css('top', plot.getPlotOffset().top + plot.height()/2 - elem.outerHeight()/2 + 'px');
|
||||
elem.css('left', '0px');
|
||||
}
|
||||
plot.getPlaceholder().append(elem);
|
||||
}
|
||||
});
|
||||
secondPass = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
$.plot.plugins.push({
|
||||
init: init,
|
||||
options: options,
|
||||
name: 'axisLabels',
|
||||
version: '1.0'
|
||||
});
|
||||
})(jQuery);
|
44
docs/benchmarks/regressions.css
Normal file
44
docs/benchmarks/regressions.css
Normal file
|
@ -0,0 +1,44 @@
|
|||
#regressions-body {
|
||||
margin-left: 2em;
|
||||
margin-right: 2em;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
#regressions-body table thead th {
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#regressions-body table thead th.desc:after {
|
||||
content: ' \2191';
|
||||
}
|
||||
|
||||
#regressions-body table thead th.asc:after {
|
||||
content: ' \2193';
|
||||
}
|
||||
|
||||
#regressions-body table.ignored {
|
||||
padding-top: 1em;
|
||||
color: #ccc;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#regressions-body table.ignored a {
|
||||
color: #82abda;
|
||||
}
|
||||
|
||||
#regressions-body .feed-div {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#regressions-body table tbody td.date {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#regressions-body table button {
|
||||
margin-top: -2px;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 0px;
|
||||
white-space: nowrap;
|
||||
}
|
618
docs/benchmarks/regressions.js
Normal file
618
docs/benchmarks/regressions.js
Normal file
|
@ -0,0 +1,618 @@
|
|||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
/* Cached contents of downloaded regressions.json */
|
||||
var regression_data = null;
|
||||
/* Current page title */
|
||||
var current_title = "All regressions";
|
||||
/* Whether HTML5 local storage is available */
|
||||
var local_storage_available = false;
|
||||
/* Key prefix for ignored regressions. For each ignored regression,
|
||||
a key "ignore_key_prefix + md5(benchmark_name + date_a + date_b)"
|
||||
is added to HTML5 local storage.
|
||||
*/
|
||||
var ignore_key_prefix = null;
|
||||
/* Set of ignored regressions, same information as in HTML5 local storage.
|
||||
Useful if local storage runs out of space. */
|
||||
var ignored_regressions = {};
|
||||
/* Whether to force reload on next page update */
|
||||
var skip_reload = false;
|
||||
|
||||
function load_data(params) {
|
||||
$("#title").text(current_title);
|
||||
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
/* html5 local storage available */
|
||||
local_storage_available = true;
|
||||
}
|
||||
|
||||
if (regression_data !== null) {
|
||||
// already displayed
|
||||
if (!skip_reload) {
|
||||
var main_div = display_data(regression_data, params);
|
||||
$('#regressions-body').empty();
|
||||
$('#regressions-body').append(main_div);
|
||||
}
|
||||
skip_reload = false;
|
||||
}
|
||||
else {
|
||||
var message = $('<div>Loading...</div>');
|
||||
skip_reload = false;
|
||||
$('#regressions-body').append(message);
|
||||
$.ajax({
|
||||
url: 'regressions.json' + '?timestamp=' + $.asv.main_timestamp,
|
||||
dataType: "json",
|
||||
cache: true
|
||||
}).done(function (data) {
|
||||
regression_data = data;
|
||||
var main_div = display_data(data, params);
|
||||
$('#regressions-body').empty();
|
||||
$('#regressions-body').append(main_div);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function update_url(params, reload) {
|
||||
var info = $.asv.parse_hash_string(window.location.hash);
|
||||
$.each(params || {}, function(key, value) {
|
||||
info.params[key] = value;
|
||||
});
|
||||
|
||||
var new_hash = $.asv.format_hash_string(info);
|
||||
if (new_hash != window.location.hash) {
|
||||
if (reload === undefined) {
|
||||
skip_reload = false;
|
||||
}
|
||||
else {
|
||||
skip_reload = !reload;
|
||||
}
|
||||
window.location.hash = new_hash;
|
||||
}
|
||||
else {
|
||||
skip_reload = false;
|
||||
}
|
||||
}
|
||||
|
||||
function display_data(data, params) {
|
||||
var main_div = $('<div/>');
|
||||
var branches = $.asv.main_json.params['branch'];
|
||||
var all_ignored_keys = {};
|
||||
|
||||
ignore_key_prefix = 'asv-r-' + $.asv.main_json.project;
|
||||
|
||||
if (branches && branches.length > 1) {
|
||||
/* Add a branch selector */
|
||||
var dropdown_menu = $('<ul class="dropdown-menu" role="menu"/>');
|
||||
var dropdown_div = $('<div class="dropdown">');
|
||||
|
||||
dropdown_div.append($('<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Branches ' +
|
||||
'<span class="caret"/></button>'));
|
||||
dropdown_div.append(dropdown_menu);
|
||||
|
||||
main_div.append(dropdown_div);
|
||||
}
|
||||
|
||||
var feed_div = $('<div class="feed-div"><a class="btn" href="regressions.xml">Feed (Atom)</a></div>');
|
||||
main_div.append(feed_div);
|
||||
|
||||
var group_div = $('<div>');
|
||||
var group_button = $('<button class="btn btn-small"/>');
|
||||
if (params.grouped) {
|
||||
group_button.text('Ungroup regressions');
|
||||
group_button.on('click', function(evt) {
|
||||
update_url({'grouped': []});
|
||||
});
|
||||
}
|
||||
else {
|
||||
group_button.text('Group regressions');
|
||||
group_button.on('click', function(evt) {
|
||||
update_url({'grouped': ["true"]});
|
||||
});
|
||||
}
|
||||
group_div.append(group_button);
|
||||
main_div.append(group_div);
|
||||
|
||||
$.each(branches, function(i, branch) {
|
||||
var branch_div = $('<div class="regression-div"/>')
|
||||
|
||||
var display_table = $('<table class="table table-hover"/>');
|
||||
var ignored_table = $('<table class="table table-hover ignored"/>');
|
||||
var ignored_button = $('<button class="btn btn-default">Show ignored regressions...</button>');
|
||||
var ignored_conf_sample_div = $('<div class="ignored"/>');
|
||||
|
||||
if (branches && branches.length > 1) {
|
||||
var branch_link = $('<a/>')
|
||||
branch_link.text(branch);
|
||||
|
||||
dropdown_menu.append($('<li role="presentation"/>').append(branch_link));
|
||||
branch_link.on('click', function(evt) {
|
||||
current_title = "Regressions in " + branch + " branch";
|
||||
update_url({'branch': [branch]}, false);
|
||||
$("#title").text(current_title);
|
||||
$(".regression-div").hide();
|
||||
$(".ignored").hide();
|
||||
ignored_button.show();
|
||||
$("#regression-div-" + i).show();
|
||||
$("#regression-div-" + i + '-ignored').show();
|
||||
});
|
||||
}
|
||||
else {
|
||||
branch = null;
|
||||
}
|
||||
|
||||
branch_div.attr('id', 'regression-div-' + i);
|
||||
branch_div.hide();
|
||||
main_div.append(branch_div);
|
||||
|
||||
if (params.grouped) {
|
||||
create_grouped_data_table(display_table, ignored_table, ignored_conf_sample_div,
|
||||
data, params, branch, all_ignored_keys);
|
||||
}
|
||||
else {
|
||||
create_data_table(display_table, ignored_table, ignored_conf_sample_div,
|
||||
data, params, branch, all_ignored_keys);
|
||||
}
|
||||
branch_div.append(display_table);
|
||||
ignored_table.hide();
|
||||
ignored_conf_sample_div.hide();
|
||||
|
||||
branch_div.append(ignored_table);
|
||||
branch_div.append(ignored_conf_sample_div);
|
||||
|
||||
update_ignore_conf_sample(data, ignored_conf_sample_div, branch);
|
||||
|
||||
branch_div.append(ignored_button);
|
||||
ignored_button.on('click', function(evt) {
|
||||
ignored_button.hide();
|
||||
$(".ignored").show();
|
||||
});
|
||||
});
|
||||
|
||||
var branch_index = 0;
|
||||
if (branches && branches.length > 1) {
|
||||
if (params.branch) {
|
||||
branch_index = branches.indexOf(params.branch[0]);
|
||||
if (branch_index < 0) {
|
||||
branch_index = 0;
|
||||
}
|
||||
}
|
||||
current_title = "Regressions in " + branches[branch_index] + " branch";
|
||||
}
|
||||
$("#title").text(current_title);
|
||||
main_div.find("#regression-div-" + branch_index).show();
|
||||
main_div.show();
|
||||
|
||||
if (local_storage_available) {
|
||||
/* Clear out local storage space */
|
||||
var keys = Object.keys(localStorage);
|
||||
$.each(keys, function(i, key) {
|
||||
if (key.slice(0, ignore_key_prefix.length) == ignore_key_prefix &&
|
||||
!all_ignored_keys[key]) {
|
||||
delete localStorage[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return main_div;
|
||||
}
|
||||
|
||||
function create_data_table(display_table, ignored_table, ignored_conf_sample_div,
|
||||
data, params, branch, all_ignored_keys) {
|
||||
var table_head = $('<thead><tr>' +
|
||||
'<th data-sort="string">Benchmark</th>' +
|
||||
'<th data-sort="string">Date</th>' +
|
||||
'<th data-sort="string">Commit</th>' +
|
||||
'<th data-sort="factor">Factor</th>' +
|
||||
'<th data-sort="value">Before</th>' +
|
||||
'<th data-sort="value">Best after</th>' +
|
||||
'<th></th>' +
|
||||
'</tr></thead>');
|
||||
|
||||
display_table.append(table_head);
|
||||
ignored_table.append(table_head.clone());
|
||||
|
||||
var table_body = $('<tbody/>');
|
||||
var ignored_table_body = $('<tbody/>');
|
||||
|
||||
var regressions = data['regressions'];
|
||||
|
||||
$.each(regressions, function (i, item) {
|
||||
var benchmark_name = item[0];
|
||||
var graph_url = item[1];
|
||||
var param_dict = item[2];
|
||||
var parameter_idx = item[3];
|
||||
var last_value = item[4];
|
||||
var best_value = item[5];
|
||||
var jumps = item[6]; // [[rev1, rev2, before, after], ...]
|
||||
|
||||
if (jumps === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (branch !== null && param_dict['branch'] != branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
var benchmark_basename = benchmark_name.replace(/\([\s\S]*/, '');
|
||||
var benchmark = $.asv.main_json.benchmarks[benchmark_basename];
|
||||
var url_params = {};
|
||||
|
||||
$.each(param_dict, function (key, value) {
|
||||
url_params[key] = [value];
|
||||
});
|
||||
|
||||
if (parameter_idx !== null) {
|
||||
$.each($.asv.param_selection_from_flat_idx(benchmark.params, parameter_idx).slice(1), function(i, param_values) {
|
||||
url_params['p-'+benchmark.param_names[i]] = [benchmark.params[i][param_values[0]]];
|
||||
});
|
||||
}
|
||||
|
||||
$.each(jumps, function(i, revs) {
|
||||
var row = $('<tr/>');
|
||||
|
||||
var commit_a = $.asv.get_commit_hash(revs[0]);
|
||||
var commit_b = $.asv.get_commit_hash(revs[1]);
|
||||
|
||||
var old_value = revs[2];
|
||||
var new_value = revs[3];
|
||||
|
||||
var factor = new_value / old_value;
|
||||
|
||||
if (commit_a) {
|
||||
url_params.commits = [commit_a + '-' + commit_b];
|
||||
}
|
||||
else {
|
||||
url_params.commits = [commit_b];
|
||||
}
|
||||
|
||||
var benchmark_url = $.asv.format_hash_string({
|
||||
location: [benchmark_basename],
|
||||
params: url_params
|
||||
});
|
||||
|
||||
new_value = $.asv.pretty_unit(new_value, benchmark.unit);
|
||||
old_value = $.asv.pretty_unit(old_value, benchmark.unit);
|
||||
|
||||
var benchmark_link = $('<a/>').attr('href', benchmark_url).text(benchmark_name);
|
||||
row.append($('<td/>').append(benchmark_link));
|
||||
|
||||
var date_fmt = new Date($.asv.main_json.revision_to_date[revs[1]]);
|
||||
row.append($('<td class="date"/>').text($.asv.format_date_yyyymmdd_hhmm(date_fmt)));
|
||||
|
||||
var commit_td = $('<td/>');
|
||||
|
||||
if (commit_a) {
|
||||
if ($.asv.main_json.show_commit_url.match(/.*\/\/github.com\//)) {
|
||||
var commit_url = ($.asv.main_json.show_commit_url + '../compare/'
|
||||
+ commit_a + '...' + commit_b);
|
||||
commit_td.append(
|
||||
$('<a/>').attr('href', commit_url).text(commit_a + '..' + commit_b));
|
||||
}
|
||||
else {
|
||||
commit_td.append($('<span/>').text(commit_a + '..' + commit_b));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var commit_url = $.asv.main_json.show_commit_url + commit_b;
|
||||
commit_td.append(
|
||||
$('<a/>').attr('href', commit_url).text(commit_b));
|
||||
}
|
||||
|
||||
row.append(commit_td);
|
||||
|
||||
row.append($('<td/>').text(factor.toFixed(2) + 'x'));
|
||||
row.append($('<td/>').text(old_value));
|
||||
row.append($('<td/>').text(new_value));
|
||||
|
||||
/* html5 local storage has limited size, so store hashes
|
||||
rather than potentially long strings */
|
||||
var ignore_key = get_ignore_key(item, revs);
|
||||
all_ignored_keys[ignore_key] = 1;
|
||||
|
||||
var is_ignored = is_key_ignored(ignore_key);
|
||||
var ignore_button = $('<button class="btn btn-small"/>');
|
||||
|
||||
row.attr('id', ignore_key);
|
||||
|
||||
ignore_button.on('click', function(evt) {
|
||||
if (is_key_ignored(ignore_key)) {
|
||||
set_key_ignore_status(ignore_key, false);
|
||||
var item = ignored_table_body.find('#' + ignore_key).detach();
|
||||
ignore_button.text('Ignore');
|
||||
table_body.append(item);
|
||||
}
|
||||
else {
|
||||
set_key_ignore_status(ignore_key, true);
|
||||
var item = table_body.find('#' + ignore_key).detach();
|
||||
ignore_button.text('Unignore');
|
||||
ignored_table_body.append(item);
|
||||
}
|
||||
update_ignore_conf_sample(data, ignored_conf_sample_div, branch);
|
||||
});
|
||||
|
||||
row.append($('<td/>').append(ignore_button));
|
||||
|
||||
if (!is_ignored) {
|
||||
ignore_button.text('Ignore');
|
||||
table_body.append(row);
|
||||
}
|
||||
else {
|
||||
ignore_button.text('Unignore');
|
||||
ignored_table_body.append(row);
|
||||
}
|
||||
|
||||
/* Show a graph as a popup */
|
||||
$.asv.ui.hover_graph(benchmark_link, graph_url, benchmark_basename, parameter_idx, [revs]);
|
||||
});
|
||||
});
|
||||
|
||||
display_table.append(table_body);
|
||||
ignored_table.append(ignored_table_body);
|
||||
|
||||
setup_sort(params, display_table);
|
||||
setup_sort(params, ignored_table);
|
||||
}
|
||||
|
||||
function create_grouped_data_table(display_table, ignored_table, ignored_conf_sample_div,
|
||||
data, params, branch, all_ignored_keys) {
|
||||
var table_head = $('<thead><tr>' +
|
||||
'<th data-sort="string">Benchmark</th>' +
|
||||
'<th data-sort="string">Last date</th>' +
|
||||
'<th data-sort="string">Commits</th>' +
|
||||
'<th data-sort="factor">Factor</th>' +
|
||||
'<th data-sort="value">Best</th>' +
|
||||
'<th data-sort="value">Current</th>' +
|
||||
'<th></th>' +
|
||||
'</tr></thead>');
|
||||
|
||||
display_table.append(table_head);
|
||||
ignored_table.append(table_head.clone());
|
||||
|
||||
var table_body = $('<tbody/>');
|
||||
var regressions = data['regressions'];
|
||||
|
||||
$.each(regressions, function (i, item) {
|
||||
var benchmark_name = item[0];
|
||||
var graph_url = item[1];
|
||||
var param_dict = item[2];
|
||||
var parameter_idx = item[3];
|
||||
var last_value = item[4];
|
||||
var best_value = item[5];
|
||||
var jumps = item[6]; // [[rev1, rev2, before, after], ...]
|
||||
|
||||
if (jumps === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (branch !== null && param_dict['branch'] != branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
var benchmark_basename = benchmark_name.replace(/\(.*/, '');
|
||||
var benchmark = $.asv.main_json.benchmarks[benchmark_basename];
|
||||
var url_params = {};
|
||||
|
||||
$.each(param_dict, function (key, value) {
|
||||
url_params[key] = [value];
|
||||
});
|
||||
|
||||
if (parameter_idx !== null) {
|
||||
$.each($.asv.param_selection_from_flat_idx(benchmark.params, parameter_idx).slice(1), function(i, param_values) {
|
||||
url_params['p-'+benchmark.param_names[i]] = [benchmark.params[i][param_values[0]]];
|
||||
});
|
||||
}
|
||||
|
||||
url_params.commits = [];
|
||||
|
||||
var commit_td = $('<td/>');
|
||||
|
||||
$.each(jumps, function(i, revs) {
|
||||
var commit_a = $.asv.get_commit_hash(revs[0]);
|
||||
var commit_b = $.asv.get_commit_hash(revs[1]);
|
||||
|
||||
if (commit_a) {
|
||||
url_params.commits = url_params.commits.concat([commit_a + '-' + commit_b]);
|
||||
}
|
||||
else {
|
||||
url_params.commits = url_params.commits.concat([commit_b]);
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
commit_td.append($('<span>, </span>'));
|
||||
}
|
||||
|
||||
if (commit_a) {
|
||||
if ($.asv.main_json.show_commit_url.match(/.*\/\/github.com\//)) {
|
||||
var commit_url = ($.asv.main_json.show_commit_url + '../compare/'
|
||||
+ commit_a + '...' + commit_b);
|
||||
commit_td.append(
|
||||
$('<a/>').attr('href', commit_url).text(commit_a + '..' + commit_b));
|
||||
}
|
||||
else {
|
||||
commit_td.append($('<span/>').text(commit_a + '..' + commit_b));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var commit_url = $.asv.main_json.show_commit_url + commit_b;
|
||||
commit_td.append(
|
||||
$('<a/>').attr('href', commit_url).text(commit_b));
|
||||
}
|
||||
});
|
||||
|
||||
var row = $('<tr/>');
|
||||
|
||||
var benchmark_url = $.asv.format_hash_string({
|
||||
location: [benchmark_basename],
|
||||
params: url_params
|
||||
});
|
||||
|
||||
var benchmark_link = $('<a/>').attr('href', benchmark_url).text(benchmark_name);
|
||||
$.asv.ui.hover_graph(benchmark_link, graph_url, benchmark_basename, parameter_idx, jumps);
|
||||
row.append($('<td/>').append(benchmark_link));
|
||||
|
||||
var date_td = $('<td class="date"/>');
|
||||
var date_fmt = new Date($.asv.main_json.revision_to_date[jumps[jumps.length-1][1]]);
|
||||
date_td.text($.asv.format_date_yyyymmdd_hhmm(date_fmt));
|
||||
row.append(date_td);
|
||||
|
||||
row.append(commit_td);
|
||||
|
||||
var factor_td = $('<td/>');
|
||||
row.append(factor_td);
|
||||
var factor = last_value / best_value;
|
||||
factor_td.text(factor.toFixed(2) + 'x');
|
||||
|
||||
var best_td = $('<td/>');
|
||||
best_td.text($.asv.pretty_unit(best_value, benchmark.unit));
|
||||
row.append(best_td);
|
||||
|
||||
var last_td = $('<td/>');
|
||||
last_td.text($.asv.pretty_unit(last_value, benchmark.unit));
|
||||
row.append(last_td);
|
||||
|
||||
table_body.append(row);
|
||||
});
|
||||
|
||||
display_table.append(table_body);
|
||||
|
||||
setup_sort(params, display_table);
|
||||
}
|
||||
|
||||
function get_ignore_key(item, revs) {
|
||||
var benchmark_name = item[0];
|
||||
var ignore_payload = benchmark_name;
|
||||
|
||||
if (revs[0] === null) {
|
||||
ignore_payload = ignore_payload + ',';
|
||||
}
|
||||
else {
|
||||
ignore_payload = (ignore_payload + ','
|
||||
+ $.asv.main_json.revision_to_hash[revs[0]]);
|
||||
}
|
||||
ignore_payload = (ignore_payload + ','
|
||||
+ $.asv.main_json.revision_to_hash[revs[1]]);
|
||||
|
||||
return ignore_key_prefix + md5(ignore_payload);
|
||||
}
|
||||
|
||||
function is_key_ignored(ignore_key) {
|
||||
if (local_storage_available) {
|
||||
return (ignore_key in localStorage) || (ignore_key in ignored_regressions);
|
||||
}
|
||||
else {
|
||||
return (ignore_key in ignored_regressions);
|
||||
}
|
||||
}
|
||||
|
||||
function set_key_ignore_status(ignore_key, is_ignored) {
|
||||
if (is_ignored) {
|
||||
if (local_storage_available) {
|
||||
try {
|
||||
localStorage[ignore_key] = 1;
|
||||
} catch (err) {
|
||||
/* Out of quota -- we're just going to ignore that */
|
||||
}
|
||||
}
|
||||
ignored_regressions[ignore_key] = 1;
|
||||
}
|
||||
else {
|
||||
if (local_storage_available) {
|
||||
delete localStorage[ignore_key];
|
||||
}
|
||||
delete ignored_regressions[ignore_key];
|
||||
}
|
||||
}
|
||||
|
||||
function update_ignore_conf_sample(data, ignored_conf_sample_div, branch) {
|
||||
var regressions = data['regressions'];
|
||||
var entries = {};
|
||||
var branch_suffix = "";
|
||||
|
||||
if (branch) {
|
||||
branch_suffix = "@" + branch;
|
||||
}
|
||||
|
||||
$.each(regressions, function (i, item) {
|
||||
var param_dict = item[2];
|
||||
if (branch !== null && param_dict['branch'] != branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.each(item[6], function (i, revs) {
|
||||
var ignore_key = get_ignore_key(item, revs);
|
||||
|
||||
if (is_key_ignored(ignore_key)) {
|
||||
var benchmark_name = item[0];
|
||||
var benchmark_name_re = (benchmark_name + branch_suffix).replace(/[.?*+^$[\]\\(){}|-]/g, "\\\\$&");
|
||||
var commit = $.asv.get_commit_hash(revs[1]);
|
||||
var entry = " \"^" + benchmark_name_re + "$\": \"" + commit + "\",\n";
|
||||
entries[entry] = 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
entries = Object.keys(entries);
|
||||
entries.sort();
|
||||
|
||||
var text = "// asv.conf.json excerpt for ignoring the above permanently\n\n";
|
||||
text += " \"regressions_first_commits\": {\n";
|
||||
$.each(entries, function (i, entry) {
|
||||
text += entry;
|
||||
});
|
||||
text += " }";
|
||||
|
||||
var pre = $('<pre/>');
|
||||
pre.text(text);
|
||||
ignored_conf_sample_div.empty();
|
||||
ignored_conf_sample_div.append(pre);
|
||||
}
|
||||
|
||||
function setup_sort(params, table) {
|
||||
table.stupidtable({
|
||||
'value': function(a, b) {
|
||||
function key(s) {
|
||||
for (var k = 0; k < $.asv.time_units.length; ++k) {
|
||||
var entry = $.asv.time_units[k];
|
||||
var m = s.match('^([0-9.]+)'+entry[0]+'$');
|
||||
if (m) {
|
||||
return parseFloat(m[1]) * entry[2] * 1e-30;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return key(a) - key(b)
|
||||
},
|
||||
'factor': function(a, b) {
|
||||
return parseFloat(a.replace(/x/, '')) - parseFloat(b.replace(/x/, ''));
|
||||
}
|
||||
});
|
||||
|
||||
table.on('aftertablesort', function (event, data) {
|
||||
update_url({'sort': [data.column], 'dir': [data.direction]}, false);
|
||||
/* Update appearance */
|
||||
table.find('thead th').removeClass('asc');
|
||||
table.find('thead th').removeClass('desc');
|
||||
var th_to_sort = table.find("thead th").eq(parseInt(data.column));
|
||||
if (th_to_sort) {
|
||||
th_to_sort.addClass(data.direction);
|
||||
}
|
||||
});
|
||||
|
||||
if (params.sort && params.dir) {
|
||||
var th_to_sort = table.find("thead th").eq(parseInt(params.sort[0]));
|
||||
th_to_sort.stupidsort(params.dir[0]);
|
||||
}
|
||||
else {
|
||||
var th_to_sort = table.find("thead th").eq(3);
|
||||
th_to_sort.stupidsort("desc");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Setup display hooks
|
||||
*/
|
||||
$.asv.register_page('regressions', function(params) {
|
||||
$('#regressions-display').show()
|
||||
load_data(params);
|
||||
});
|
||||
});
|
1
docs/benchmarks/regressions.json
Normal file
1
docs/benchmarks/regressions.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"regressions": [["Components vs Django.timeraw_render_lg_subsequent('django')", "graphs/branch-master/django-5.1/djc-core-html-parser/machine-ci-linux/python-3.13/Components vs Django.timeraw_render_lg_subsequent.json", {}, 0, 0.04362213900003553, 0.03327357099999517, [[1691, 1709, 0.03327357099999517, 0.03723830100000214], [1801, 1937, 0.03723830100000214, 0.04362213900003553]]]]}
|
8
docs/benchmarks/regressions.xml
Normal file
8
docs/benchmarks/regressions.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom"><id>tag:django-components.asv,1970-01-01:/cddbdcca8b398afd301fbfc73cc4d51103d4e3059c0e6b938d4c467ad3d1aa25</id><author><name>Airspeed Velocity</name></author><title xml:lang="en">django-components performance regressions</title><updated>2025-06-04T22:41:21Z</updated><entry><id>tag:django-components.asv,2025-06-04:/38b868a38890eb5bccfd51983abf3a15cedf2846ef6cf2452e941122dbde2bde</id><title xml:lang="en">17.14% Components vs Django.timeraw_render_lg_subsequent('django')</title><updated>2025-06-04T22:41:21Z</updated><link href="index.html#Components vs Django.timeraw_render_lg_subsequent?p-renderer=%27django%27&commits=4c909486069f3c3c8ee7915239174f820f081da4-7b24b86f4a836c697acba926d9d6602afa45418d" /><content xml:lang="en" type="html"><a href="index.html#Components vs Django.timeraw_render_lg_subsequent?p-renderer=%27django%27&commits=4c909486069f3c3c8ee7915239174f820f081da4-7b24b86f4a836c697acba926d9d6602afa45418d">17.14% regression</a> on 2025-06-04 22:35:21 in commits <a href="#4c909486069f3c3c8ee7915239174f820f081da4">4c909486...7b24b86f</a>.<br>
|
||||
New value: 43.6ms, old value: 37.2ms.<br>
|
||||
Latest value: 43.6ms (31.10% worse
|
||||
than best value 33.3ms).</content></entry><entry><id>tag:django-components.asv,2025-03-31:/7a13128cbc4d175ca09ebda40e8a303789275bd84b00a5d496cfa08a26ad2f8b</id><title xml:lang="en">11.92% Components vs Django.timeraw_render_lg_subsequent('django')</title><updated>2025-03-31T14:16:53Z</updated><link href="index.html#Components vs Django.timeraw_render_lg_subsequent?p-renderer=%27django%27&commits=42818ad6ffb47bd650d8a379b84c3d48394f9f77-a6455d70f6c28ddbd4be8e58902f6cbc101e5ff3" /><content xml:lang="en" type="html"><a href="index.html#Components vs Django.timeraw_render_lg_subsequent?p-renderer=%27django%27&commits=42818ad6ffb47bd650d8a379b84c3d48394f9f77-a6455d70f6c28ddbd4be8e58902f6cbc101e5ff3">11.92% regression</a> on 2025-03-31 14:10:42 in commits <a href="#42818ad6ffb47bd650d8a379b84c3d48394f9f77">42818ad6...a6455d70</a>.<br>
|
||||
New value: 37.2ms, old value: 33.3ms.<br>
|
||||
Latest value: 43.6ms (31.10% worse
|
||||
than best value 33.3ms).</content></entry></feed>
|
136
docs/benchmarks/summarygrid.js
Normal file
136
docs/benchmarks/summarygrid.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
var summary_loaded = false;
|
||||
|
||||
/* Callback a function when an element comes in view */
|
||||
function callback_in_view(element, func) {
|
||||
function handler(evt) {
|
||||
var visible = (
|
||||
$('#summarygrid-display').css('display') != 'none' &&
|
||||
(element.offset().top <= $(window).height() + $(window).scrollTop()) &&
|
||||
(element.offset().top + element.height() >= $(window).scrollTop()));
|
||||
if (visible) {
|
||||
func();
|
||||
$(window).off('scroll', handler);
|
||||
}
|
||||
}
|
||||
$(window).on('scroll', handler);
|
||||
}
|
||||
|
||||
function get_benchmarks_by_groups() {
|
||||
var main_json = $.asv.main_json;
|
||||
var groups = {};
|
||||
$.each(main_json.benchmarks, function(bm_name, bm) {
|
||||
var i = bm_name.indexOf('.');
|
||||
var group = bm_name.slice(0, i);
|
||||
var name = bm_name.slice(i + 1);
|
||||
if (groups[group] === undefined) {
|
||||
groups[group] = [];
|
||||
}
|
||||
groups[group].push(bm_name);
|
||||
});
|
||||
return groups;
|
||||
}
|
||||
|
||||
function benchmark_container(bm) {
|
||||
var container = $(
|
||||
'<a class="btn benchmark-container" href="#' + bm.name +
|
||||
'"/>');
|
||||
var plot_div = $(
|
||||
'<div id="summarygrid-' + bm.name + '" class="benchmark-plot"/>');
|
||||
var display_name = bm.pretty_name || bm.name.slice(bm.name.indexOf('.') + 1);
|
||||
var name = $('<div class="benchmark-text">' + display_name + '</div>');
|
||||
name.tooltip({
|
||||
title: bm.name,
|
||||
html: true,
|
||||
placement: 'top',
|
||||
container: 'body',
|
||||
animation: false
|
||||
});
|
||||
|
||||
plot_div.tooltip({
|
||||
title: bm.code,
|
||||
html: true,
|
||||
placement: 'bottom',
|
||||
container: 'body',
|
||||
animation: false
|
||||
});
|
||||
|
||||
container.append(name);
|
||||
container.append(plot_div);
|
||||
|
||||
callback_in_view(plot_div, function() {
|
||||
$.asv.load_graph_data(
|
||||
'graphs/summary/' + bm.name + '.json'
|
||||
).done(function(data) {
|
||||
var options = {
|
||||
colors: $.asv.colors,
|
||||
series: {
|
||||
lines: {
|
||||
show: true,
|
||||
lineWidth: 2
|
||||
},
|
||||
shadowSize: 0
|
||||
},
|
||||
grid: {
|
||||
borderWidth: 1,
|
||||
margin: 0,
|
||||
labelMargin: 0,
|
||||
axisMargin: 0,
|
||||
minBorderMargin: 0
|
||||
},
|
||||
xaxis: {
|
||||
ticks: [],
|
||||
},
|
||||
yaxis: {
|
||||
ticks: [],
|
||||
min: 0
|
||||
},
|
||||
legend: {
|
||||
show: false
|
||||
}
|
||||
};
|
||||
|
||||
var plot = $.plot(
|
||||
plot_div, [{data: data}], options);
|
||||
}).fail(function() {
|
||||
// TODO: Handle failure
|
||||
});
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
function make_summary() {
|
||||
var summary_display = $('#summarygrid-display');
|
||||
var main_json = $.asv.main_json;
|
||||
var summary_container = $('<div/>');
|
||||
|
||||
if (summary_loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.each(get_benchmarks_by_groups(), function(group, benchmarks) {
|
||||
var group_container = $('<div class="benchmark-group"/>')
|
||||
group_container.attr('id', 'group-' + group)
|
||||
group_container.append($('<h1>' + group + '</h1>'));
|
||||
summary_display.append(group_container);
|
||||
$.each(benchmarks, function(i, bm_name) {
|
||||
var bm = $.asv.main_json.benchmarks[bm_name];
|
||||
group_container.append(benchmark_container(bm));
|
||||
});
|
||||
});
|
||||
|
||||
summary_display.append(summary_container);
|
||||
$(window).trigger('scroll');
|
||||
|
||||
summary_loaded = true;
|
||||
}
|
||||
|
||||
$.asv.register_page('', function(params) {
|
||||
$('#summarygrid-display').show();
|
||||
$("#title").text("All benchmarks");
|
||||
$('.tooltip').remove();
|
||||
make_summary();
|
||||
});
|
||||
});
|
50
docs/benchmarks/summarylist.css
Normal file
50
docs/benchmarks/summarylist.css
Normal file
|
@ -0,0 +1,50 @@
|
|||
#summarylist-body {
|
||||
padding-left: 2em;
|
||||
padding-right: 2em;
|
||||
padding-top: 1em;
|
||||
padding-bottom: 2em;
|
||||
}
|
||||
|
||||
#summarylist-body table thead th {
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#summarylist-body table thead th.desc:after {
|
||||
content: ' \2191';
|
||||
}
|
||||
|
||||
#summarylist-body table thead th.asc:after {
|
||||
content: ' \2193';
|
||||
}
|
||||
|
||||
#summarylist-body table.ignored {
|
||||
padding-top: 1em;
|
||||
color: #ccc;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#summarylist-body table.ignored a {
|
||||
color: #82abda;
|
||||
}
|
||||
|
||||
#summarylist-body table tbody td.positive-change {
|
||||
background-color: #fdd;
|
||||
}
|
||||
|
||||
#summarylist-body table tbody td.negative-change {
|
||||
background-color: #dfd;
|
||||
}
|
||||
|
||||
#summarylist-body table tbody td.value {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#summarylist-body table tbody td.change a {
|
||||
color: black;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#summarylist-body table tbody td.change-date {
|
||||
white-space: nowrap;
|
||||
}
|
451
docs/benchmarks/summarylist.js
Normal file
451
docs/benchmarks/summarylist.js
Normal file
|
@ -0,0 +1,451 @@
|
|||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
/* The state of the parameters in the sidebar. Dictionary mapping
|
||||
strings to values determining the "enabled" configurations. */
|
||||
var state = null;
|
||||
/* Cache of constructed tables, {data_path: table_dom_id} */
|
||||
var table_cache = {};
|
||||
var table_cache_counter = 0;
|
||||
|
||||
function setup_display(state_selection) {
|
||||
var new_state = setup_state(state_selection);
|
||||
var same_state = (state !== null);
|
||||
|
||||
/* Avoid needless UI updates, e.g., on table sort */
|
||||
|
||||
if (same_state) {
|
||||
$.each(state, function (key, value) {
|
||||
if (value != new_state[key]) {
|
||||
same_state = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!same_state) {
|
||||
state = new_state;
|
||||
replace_params_ui();
|
||||
|
||||
var filename = $.asv.graph_to_path('summary', state);
|
||||
|
||||
$("#summarylist-body table").hide();
|
||||
$("#summarylist-body .message").remove();
|
||||
|
||||
if (table_cache[filename] !== undefined) {
|
||||
$(table_cache[filename]).show();
|
||||
}
|
||||
else {
|
||||
$("#summarylist-body").append($("<p class='message'>Loading...</p>"));
|
||||
$.asv.load_graph_data(
|
||||
filename
|
||||
).done(function (data) {
|
||||
var table = construct_benchmark_table(data);
|
||||
var table_name = 'summarylist-table-' + table_cache_counter;
|
||||
++table_cache_counter;
|
||||
|
||||
table.attr('id', table_name);
|
||||
table_cache[filename] = '#' + table_name;
|
||||
$("#summarylist-body .message").remove();
|
||||
$("#summarylist-body").append(table);
|
||||
table.show()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update_state_url(key, value) {
|
||||
var info = $.asv.parse_hash_string(window.location.hash);
|
||||
var new_state = get_valid_state(state, key, value);
|
||||
|
||||
$.each($.asv.main_json.params, function(param, values) {
|
||||
if (values.length > 1) {
|
||||
info.params[param] = [new_state[param]];
|
||||
}
|
||||
else if (info.params[param]) {
|
||||
delete info.params[param];
|
||||
}
|
||||
});
|
||||
|
||||
window.location.hash = $.asv.format_hash_string(info);
|
||||
}
|
||||
|
||||
function obj_copy(obj) {
|
||||
var newobj = {};
|
||||
$.each(obj, function(key, val) {
|
||||
newobj[key] = val;
|
||||
});
|
||||
return newobj;
|
||||
}
|
||||
|
||||
function obj_diff(obj1, obj2) {
|
||||
var count = 0;
|
||||
$.each(obj1, function(key, val) {
|
||||
if (obj2[key] != val) {
|
||||
++count
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
function get_valid_state(tmp_state, wanted_key, wanted_value) {
|
||||
/*
|
||||
Get an available state with wanted_key having wanted_value,
|
||||
preferably as a minor modification of tmp_state.
|
||||
*/
|
||||
var best_params = null;
|
||||
var best_diff = 1e99;
|
||||
var best_hit = false;
|
||||
|
||||
tmp_state = obj_copy(tmp_state);
|
||||
if (wanted_key !== undefined) {
|
||||
tmp_state[wanted_key] = wanted_value;
|
||||
}
|
||||
|
||||
$.each($.asv.main_json.graph_param_list, function(idx, params) {
|
||||
var diff = obj_diff(tmp_state, params);
|
||||
var hit = (wanted_key === undefined || params[wanted_key] == wanted_value);
|
||||
|
||||
if ((!best_hit && hit) || (hit == best_hit && diff < best_diff)) {
|
||||
best_params = params;
|
||||
best_diff = diff;
|
||||
best_hit = hit;
|
||||
}
|
||||
});
|
||||
|
||||
if (best_params === null) {
|
||||
best_params = $.asv.main_json.graph_param_list[0];
|
||||
}
|
||||
|
||||
return obj_copy(best_params);
|
||||
}
|
||||
|
||||
function setup_state(state_selection) {
|
||||
var index = $.asv.main_json;
|
||||
var state = {};
|
||||
|
||||
state.machine = index.params.machine;
|
||||
|
||||
$.each(index.params, function(param, values) {
|
||||
state[param] = values[0];
|
||||
});
|
||||
|
||||
if (state_selection !== null) {
|
||||
/* Select a specific generic parameter state */
|
||||
$.each(index.params, function(param, values) {
|
||||
if (state_selection[param]) {
|
||||
state[param] = state_selection[param][0];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return get_valid_state(state);
|
||||
}
|
||||
|
||||
function replace_params_ui() {
|
||||
var index = $.asv.main_json;
|
||||
|
||||
var nav = $('#summarylist-navigation');
|
||||
nav.empty();
|
||||
|
||||
/* Machine selection */
|
||||
$.asv.ui.make_value_selector_panel(nav, 'machine', index.params.machine, function(i, machine, button) {
|
||||
button.text(machine);
|
||||
|
||||
button.on('click', function(evt) {
|
||||
update_state_url('machine', machine);
|
||||
});
|
||||
|
||||
if (state.machine != machine) {
|
||||
button.removeClass('active');
|
||||
}
|
||||
button.removeAttr('data-toggle');
|
||||
|
||||
/* Create tooltips for each machine */
|
||||
var details = [];
|
||||
$.each(index.machines[machine], function(key, val) {
|
||||
details.push(key + ': ' + val);
|
||||
});
|
||||
details = details.join('<br/>');
|
||||
|
||||
button.tooltip({
|
||||
title: details,
|
||||
html: true,
|
||||
placement: 'right',
|
||||
container: 'body',
|
||||
animation: false
|
||||
});
|
||||
});
|
||||
|
||||
/* Generic parameter selectors */
|
||||
$.each(index.params, function(param, values) {
|
||||
if (values.length > 1 && param != 'machine') {
|
||||
$.asv.ui.make_value_selector_panel(nav, param, values, function(i, value, button) {
|
||||
var value_display;
|
||||
if (value === null)
|
||||
value_display = '[none]';
|
||||
else if (!value)
|
||||
value_display = '[default]';
|
||||
else
|
||||
value_display = value;
|
||||
|
||||
button.text(value_display);
|
||||
|
||||
if (state[param] != value) {
|
||||
button.removeClass('active');
|
||||
}
|
||||
|
||||
button.on('click', function(evt) {
|
||||
update_state_url(param, value);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(nav).find(".btn-group").removeAttr("data-toggle");
|
||||
|
||||
$.asv.ui.reflow_value_selector_panels();
|
||||
}
|
||||
|
||||
function construct_benchmark_table(data) {
|
||||
var index = $.asv.main_json;
|
||||
|
||||
/* Form a new table */
|
||||
|
||||
var table = $('<table class="table table-hover"/>');
|
||||
|
||||
var table_head = $('<thead><tr>' +
|
||||
'<th data-sort="string">Benchmark</th>' +
|
||||
'<th data-sort="float">Value</th>' +
|
||||
'<th data-sort="float">Recent change</th>' +
|
||||
'<th data-sort="string">Changed at</th>' +
|
||||
'</tr></thead>');
|
||||
table.append(table_head);
|
||||
|
||||
var table_body = $('<tbody/>');
|
||||
|
||||
$.each(data, function(row_idx, row) {
|
||||
var tr = $('<tr/>');
|
||||
var name_td = $('<td/>');
|
||||
var name = $('<a/>');
|
||||
var benchmark_url_args = {};
|
||||
var benchmark_full_url;
|
||||
var benchmark_base_url;
|
||||
|
||||
/* Format benchmark url */
|
||||
benchmark_url_args.location = [row.name];
|
||||
benchmark_url_args.params = {};
|
||||
$.each($.asv.main_json.params, function (key, values) {
|
||||
if (values.length > 1) {
|
||||
benchmark_url_args.params[key] = [state[key]];
|
||||
}
|
||||
});
|
||||
benchmark_base_url = $.asv.format_hash_string(benchmark_url_args);
|
||||
if (row.idx !== null) {
|
||||
var benchmark = $.asv.main_json.benchmarks[row.name];
|
||||
$.each($.asv.param_selection_from_flat_idx(benchmark.params, row.idx).slice(1),
|
||||
function(i, param_values) {
|
||||
benchmark_url_args.params['p-'+benchmark.param_names[i]]
|
||||
= [benchmark.params[i][param_values[0]]];
|
||||
});
|
||||
}
|
||||
benchmark_full_url = $.asv.format_hash_string(benchmark_url_args);
|
||||
|
||||
/* Benchmark name column */
|
||||
var bm_link;
|
||||
if (row.idx === null) {
|
||||
bm_link = $('<a/>').attr('href', benchmark_base_url).text(row.pretty_name);
|
||||
name_td.append(bm_link);
|
||||
}
|
||||
else {
|
||||
var basename = row.pretty_name;
|
||||
var args = null;
|
||||
var m = row.pretty_name.match(/(.*)\(.*$/);
|
||||
if (m) {
|
||||
basename = m[1];
|
||||
args = row.pretty_name.slice(basename.length);
|
||||
}
|
||||
bm_link = $('<a/>').attr('href', benchmark_base_url).text(basename);
|
||||
name_td.append(bm_link);
|
||||
if (args) {
|
||||
var bm_idx_link;
|
||||
var graph_url;
|
||||
bm_idx_link = $('<a/>').attr('href', benchmark_full_url).text(' ' + args);
|
||||
name_td.append(bm_idx_link);
|
||||
graph_url = $.asv.graph_to_path(row.name, state);
|
||||
$.asv.ui.hover_graph(bm_idx_link, graph_url, row.name, row.idx, null);
|
||||
}
|
||||
}
|
||||
$.asv.ui.hover_summary_graph(bm_link, row.name);
|
||||
|
||||
/* Value column */
|
||||
var value_td = $('<td class="value"/>');
|
||||
if (row.last_value !== null) {
|
||||
var value, err, err_str, sort_value;
|
||||
var unit = $.asv.main_json.benchmarks[row.name].unit;
|
||||
value = $.asv.pretty_unit(row.last_value, unit);
|
||||
if (unit == "seconds") {
|
||||
sort_value = row.last_value * 1e100;
|
||||
}
|
||||
else {
|
||||
sort_value = row.last_value;
|
||||
}
|
||||
var value_span = $('<span/>').text(value);
|
||||
|
||||
err = 100*row.last_err/row.last_value;
|
||||
if (err == err) {
|
||||
err_str = " \u00b1 " + err.toFixed(0.1) + '%';
|
||||
}
|
||||
else {
|
||||
err_str = "";
|
||||
}
|
||||
value_span.attr('data-toggle', 'tooltip');
|
||||
value_span.attr('title', value + err_str);
|
||||
value_td.append(value_span);
|
||||
value_td.attr('data-sort-value', sort_value);
|
||||
}
|
||||
else {
|
||||
value_td.attr('data-sort-value', -1e99);
|
||||
}
|
||||
|
||||
/* Change percentage column */
|
||||
var change_td = $('<td class="change"/>');
|
||||
if (row.prev_value !== null) {
|
||||
var text, change_str, change = 0, sort_value = 0;
|
||||
var unit = $.asv.main_json.benchmarks[row.name].unit;
|
||||
change_str = $.asv.pretty_unit(row.last_value - row.prev_value, unit);
|
||||
if (!change_str.match(/^-/)) {
|
||||
change_str = '+' + change_str;
|
||||
}
|
||||
if (row.prev_value != 0) {
|
||||
change = 100 * (row.last_value / row.prev_value - 1);
|
||||
text = change.toFixed(1) + '% (' + change_str + ')';
|
||||
if (change > 0) {
|
||||
text = '+' + text;
|
||||
}
|
||||
sort_value = change;
|
||||
}
|
||||
else {
|
||||
text = ' (' + change_str + ')';
|
||||
}
|
||||
text = text.replace('-', '\u2212');
|
||||
|
||||
var change_commit_a = $.asv.main_json.revision_to_hash[row.change_rev[0]];
|
||||
var change_commit_b = $.asv.main_json.revision_to_hash[row.change_rev[1]];
|
||||
var change_q;
|
||||
if (change_commit_a === undefined) {
|
||||
change_q = '&commits=' + change_commit_b;
|
||||
}
|
||||
else {
|
||||
change_q = '&commits=' + change_commit_a + '-' + change_commit_b;
|
||||
}
|
||||
var change_link = $('<a/>').attr('href', benchmark_full_url + change_q).text(text);
|
||||
|
||||
graph_url = $.asv.graph_to_path(row.name, state);
|
||||
$.asv.ui.hover_graph(change_link, graph_url, row.name, row.idx, [row.change_rev]);
|
||||
|
||||
change_td.append(change_link);
|
||||
|
||||
if (change > 5) {
|
||||
change_td.addClass('positive-change');
|
||||
}
|
||||
else if (change < -5) {
|
||||
change_td.addClass('negative-change');
|
||||
}
|
||||
change_td.attr('data-sort-value', sort_value);
|
||||
}
|
||||
else {
|
||||
change_td.attr('data-sort-value', 0);
|
||||
}
|
||||
|
||||
/* Change date column */
|
||||
var changed_at_td = $('<td class="change-date"/>');
|
||||
if (row.change_rev !== null) {
|
||||
var date = new Date($.asv.main_json.revision_to_date[row.change_rev[1]]);
|
||||
var commit_1 = $.asv.get_commit_hash(row.change_rev[0]);
|
||||
var commit_2 = $.asv.get_commit_hash(row.change_rev[1]);
|
||||
var commit_a = $('<a/>');
|
||||
var span = $('<span/>');
|
||||
if (commit_1) {
|
||||
var commit_url;
|
||||
if ($.asv.main_json.show_commit_url.match(/.*\/\/github.com\//)) {
|
||||
commit_url = ($.asv.main_json.show_commit_url + '../compare/'
|
||||
+ commit_1 + '...' + commit_2);
|
||||
}
|
||||
else {
|
||||
commit_url = $.asv.main_json.show_commit_url + commit_2;
|
||||
}
|
||||
commit_a.attr('href', commit_url);
|
||||
commit_a.text(commit_1 + '...' + commit_2);
|
||||
}
|
||||
else {
|
||||
commit_a.attr('href', $.asv.main_json.show_commit_url + commit_2);
|
||||
commit_a.text(commit_2);
|
||||
}
|
||||
span.text($.asv.format_date_yyyymmdd(date) + ' ');
|
||||
span.append(commit_a);
|
||||
changed_at_td.append(span);
|
||||
}
|
||||
|
||||
tr.append(name_td);
|
||||
tr.append(value_td);
|
||||
tr.append(change_td);
|
||||
tr.append(changed_at_td);
|
||||
|
||||
table_body.append(tr);
|
||||
});
|
||||
|
||||
table_body.find('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
/* Finalize */
|
||||
table.append(table_body);
|
||||
setup_sort(table);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
function setup_sort(table) {
|
||||
var info = $.asv.parse_hash_string(window.location.hash);
|
||||
|
||||
table.stupidtable();
|
||||
|
||||
table.on('aftertablesort', function (event, data) {
|
||||
var info = $.asv.parse_hash_string(window.location.hash);
|
||||
info.params['sort'] = [data.column];
|
||||
info.params['dir'] = [data.direction];
|
||||
window.location.hash = $.asv.format_hash_string(info);
|
||||
|
||||
/* Update appearance */
|
||||
table.find('thead th').removeClass('asc');
|
||||
table.find('thead th').removeClass('desc');
|
||||
var th_to_sort = table.find("thead th").eq(parseInt(data.column));
|
||||
if (th_to_sort) {
|
||||
th_to_sort.addClass(data.direction);
|
||||
}
|
||||
});
|
||||
|
||||
if (info.params.sort && info.params.dir) {
|
||||
var th_to_sort = table.find("thead th").eq(parseInt(info.params.sort[0]));
|
||||
th_to_sort.stupidsort(info.params.dir[0]);
|
||||
}
|
||||
else {
|
||||
var th_to_sort = table.find("thead th").eq(0);
|
||||
th_to_sort.stupidsort("asc");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry point
|
||||
*/
|
||||
$.asv.register_page('summarylist', function(params) {
|
||||
var state_selection = null;
|
||||
|
||||
if (Object.keys(params).length > 0) {
|
||||
state_selection = params;
|
||||
}
|
||||
|
||||
setup_display(state_selection);
|
||||
|
||||
$('#summarylist-display').show();
|
||||
$("#title").text("List of benchmarks");
|
||||
});
|
||||
});
|
BIN
docs/benchmarks/swallow.ico
Normal file
BIN
docs/benchmarks/swallow.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
docs/benchmarks/swallow.png
Normal file
BIN
docs/benchmarks/swallow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 893 B |
4
docs/concepts/.nav.yml
Normal file
4
docs/concepts/.nav.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
# `.nav.yml` is provided by https://lukasgeiter.github.io/mkdocs-awesome-nav
|
||||
nav:
|
||||
- fundamentals
|
||||
- advanced
|
14
docs/concepts/advanced/.nav.yml
Normal file
14
docs/concepts/advanced/.nav.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
# `.nav.yml` is provided by https://lukasgeiter.github.io/mkdocs-awesome-nav
|
||||
nav:
|
||||
- Rendering JS / CSS: rendering_js_css.md
|
||||
- HTML fragments: html_fragments.md
|
||||
- Prop drilling and provide / inject: provide_inject.md
|
||||
- Lifecycle hooks: hooks.md
|
||||
- Registering components: component_registry.md
|
||||
- Component caching: component_caching.md
|
||||
- Component context and scope: component_context_scope.md
|
||||
- Custom template tags: template_tags.md
|
||||
- Tag formatters: tag_formatters.md
|
||||
- Extensions: extensions.md
|
||||
- Testing: testing.md
|
||||
- Component libraries: component_libraries.md
|
181
docs/concepts/advanced/component_caching.md
Normal file
181
docs/concepts/advanced/component_caching.md
Normal file
|
@ -0,0 +1,181 @@
|
|||
Component caching allows you to store the rendered output of a component. Next time the component is rendered
|
||||
with the same input, the cached output is returned instead of re-rendering the component.
|
||||
|
||||
This is particularly useful for components that are expensive to render or do not change frequently.
|
||||
|
||||
!!! info
|
||||
|
||||
Component caching uses [Django's cache framework](https://docs.djangoproject.com/en/5.2/topics/cache/),
|
||||
so you can use any cache backend that is supported by Django.
|
||||
|
||||
### Enabling caching
|
||||
|
||||
Caching is disabled by default.
|
||||
|
||||
To enable caching for a component, set [`Component.Cache.enabled`](../../reference/api.md#django_components.ComponentCache.enabled) to `True`:
|
||||
|
||||
```python
|
||||
from django_components import Component
|
||||
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
```
|
||||
|
||||
### Time-to-live (TTL)
|
||||
|
||||
You can specify a time-to-live (TTL) for the cache entry with [`Component.Cache.ttl`](../../reference/api.md#django_components.ComponentCache.ttl), which determines how long the entry remains valid. The TTL is specified in seconds.
|
||||
|
||||
```python
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
ttl = 60 * 60 * 24 # 1 day
|
||||
```
|
||||
|
||||
- If `ttl > 0`, entries are cached for the specified number of seconds.
|
||||
- If `ttl = -1`, entries are cached indefinitely.
|
||||
- If `ttl = 0`, entries are not cached.
|
||||
- If `ttl = None`, the default TTL is used.
|
||||
|
||||
### Custom cache name
|
||||
|
||||
Since component caching uses Django's cache framework, you can specify a custom cache name with [`Component.Cache.cache_name`](../../reference/api.md#django_components.ComponentCache.cache_name) to use a different cache backend:
|
||||
|
||||
```python
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
cache_name = "my_cache"
|
||||
```
|
||||
|
||||
### Cache key generation
|
||||
|
||||
By default, the cache key is generated based on the component's input (args and kwargs). So the following two calls would generate separate entries in the cache:
|
||||
|
||||
```py
|
||||
MyComponent.render(name="Alice")
|
||||
MyComponent.render(name="Bob")
|
||||
```
|
||||
|
||||
However, you have full control over the cache key generation. As such, you can:
|
||||
|
||||
- Cache the component on all inputs (default)
|
||||
- Cache the component on particular inputs
|
||||
- Cache the component irrespective of the inputs
|
||||
|
||||
To achieve that, you can override
|
||||
the [`Component.Cache.hash()`](../../reference/api.md#django_components.ComponentCache.hash)
|
||||
method to customize how arguments are hashed into the cache key.
|
||||
|
||||
```python
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
|
||||
def hash(self, *args, **kwargs):
|
||||
return f"{json.dumps(args)}:{json.dumps(kwargs)}"
|
||||
```
|
||||
|
||||
For even more control, you can override other methods available on the [`ComponentCache`](../../reference/api.md#django_components.ComponentCache) class.
|
||||
|
||||
!!! warning
|
||||
|
||||
The default implementation of `Cache.hash()` simply serializes the input into a string.
|
||||
As such, it might not be suitable if you need to hash complex objects like Models.
|
||||
|
||||
### Caching slots
|
||||
|
||||
By default, the cache key is generated based ONLY on the args and kwargs.
|
||||
|
||||
To cache the component based on the slots, set [`Component.Cache.include_slots`](../../reference/api.md#django_components.ComponentCache.include_slots) to `True`:
|
||||
|
||||
```python
|
||||
class MyComponent(Component):
|
||||
class Cache:
|
||||
enabled = True
|
||||
include_slots = True
|
||||
```
|
||||
|
||||
with `include_slots = True`, the cache key will be generated also based on the given slots.
|
||||
|
||||
As such, the following two calls would generate separate entries in the cache:
|
||||
|
||||
```django
|
||||
{% component "my_component" position="left" %}
|
||||
Hello, Alice
|
||||
{% endcomponent %}
|
||||
|
||||
{% component "my_component" position="left" %}
|
||||
Hello, Bob
|
||||
{% endcomponent %}
|
||||
```
|
||||
|
||||
Same when using [`Component.render()`](../../reference/api.md#django_components.Component.render) with string slots:
|
||||
|
||||
```py
|
||||
MyComponent.render(
|
||||
kwargs={"position": "left"},
|
||||
slots={"content": "Hello, Alice"}
|
||||
)
|
||||
MyComponent.render(
|
||||
kwargs={"position": "left"},
|
||||
slots={"content": "Hello, Bob"}
|
||||
)
|
||||
```
|
||||
|
||||
!!! warning
|
||||
|
||||
Passing slots as functions to cached components with `include_slots=True` will raise an error.
|
||||
|
||||
```py
|
||||
MyComponent.render(
|
||||
kwargs={"position": "left"},
|
||||
slots={"content": lambda ctx: "Hello, Alice"}
|
||||
)
|
||||
```
|
||||
|
||||
!!! warning
|
||||
|
||||
Slot caching DOES NOT account for context variables within
|
||||
the [`{% fill %}`](../../reference/template_tags.md#fill) tag.
|
||||
|
||||
For example, the following two cases will be treated as the same entry:
|
||||
|
||||
```django
|
||||
{% with my_var="foo" %}
|
||||
{% component "mycomponent" name="foo" %}
|
||||
{{ my_var }}
|
||||
{% endcomponent %}
|
||||
{% endwith %}
|
||||
|
||||
{% with my_var="bar" %}
|
||||
{% component "mycomponent" name="bar" %}
|
||||
{{ my_var }}
|
||||
{% endcomponent %}
|
||||
{% endwith %}
|
||||
```
|
||||
|
||||
Currently it's impossible to capture used variables. This will be addressed in v2.
|
||||
Read more about it in [django-components/#1164](https://github.com/django-components/django-components/issues/1164).
|
||||
|
||||
### Example
|
||||
|
||||
Here's a complete example of a component with caching enabled:
|
||||
|
||||
```python
|
||||
from django_components import Component
|
||||
|
||||
class MyComponent(Component):
|
||||
template = "Hello, {{ name }}"
|
||||
|
||||
class Cache:
|
||||
enabled = True
|
||||
ttl = 300 # Cache for 5 minutes
|
||||
cache_name = "my_cache"
|
||||
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {"name": kwargs["name"]}
|
||||
```
|
||||
|
||||
In this example, the component's rendered output is cached for 5 minutes using the `my_cache` backend.
|
|
@ -1,8 +1,3 @@
|
|||
---
|
||||
title: Component context and scope
|
||||
weight: 4
|
||||
---
|
||||
|
||||
By default, context variables are passed down the template as in regular Django - deeper scopes can access the variables from the outer scopes. So if you have several nested forloops, then inside the deep-most loop you can access variables defined by all previous loops.
|
||||
|
||||
With this in mind, the `{% component %}` tag behaves similarly to `{% include %}` tag - inside the component tag, you can access all variables that were defined outside of it.
|
||||
|
@ -17,7 +12,7 @@ NOTE: `{% csrf_token %}` tags need access to the top-level context, and they wil
|
|||
|
||||
If you find yourself using the `only` modifier often, you can set the [context_behavior](#context-behavior) option to `"isolated"`, which automatically applies the `only` modifier. This is useful if you want to make sure that components don't accidentally access the outer context.
|
||||
|
||||
Components can also access the outer context in their context methods like `get_context_data` by accessing the property `self.outer_context`.
|
||||
Components can also access the outer context in their context methods like `get_template_data` by accessing the property `self.outer_context`.
|
||||
|
||||
## Example of Accessing Outer Context
|
||||
|
||||
|
@ -27,14 +22,14 @@ Components can also access the outer context in their context methods like `get_
|
|||
</div>
|
||||
```
|
||||
|
||||
Assuming that the rendering context has variables such as `date`, you can use `self.outer_context` to access them from within `get_context_data`. Here's how you might implement it:
|
||||
Assuming that the rendering context has variables such as `date`, you can use `self.outer_context` to access them from within `get_template_data`. Here's how you might implement it:
|
||||
|
||||
```python
|
||||
class Calender(Component):
|
||||
|
||||
...
|
||||
|
||||
def get_context_data(self):
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
outer_field = self.outer_context["date"]
|
||||
return {
|
||||
"date": outer_fields,
|
||||
|
@ -58,10 +53,10 @@ This has two modes:
|
|||
you can access are a union of:
|
||||
|
||||
- All the variables that were OUTSIDE the fill tag, including any\
|
||||
[`{% with %}`](https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#with) tags.
|
||||
- Any loops ([`{% for ... %}`](https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#cycle))
|
||||
[`{% with %}`](https://docs.djangoproject.com/en/5.2/ref/templates/builtins/#with) tags.
|
||||
- Any loops ([`{% for ... %}`](https://docs.djangoproject.com/en/5.2/ref/templates/builtins/#cycle))
|
||||
that the `{% fill %}` tag is part of.
|
||||
- Data returned from [`Component.get_context_data()`](../../../reference/api#django_components.Component.get_context_data)
|
||||
- Data returned from [`Component.get_template_data()`](../../../reference/api#django_components.Component.get_template_data)
|
||||
of the component that owns the fill tag.
|
||||
|
||||
- `"isolated"`
|
||||
|
@ -72,22 +67,22 @@ This has two modes:
|
|||
|
||||
Inside the [`{% fill %}`](../../../reference/template_tags#fill) tag, you can ONLY access variables from 2 places:
|
||||
|
||||
- Any loops ([`{% for ... %}`](https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#cycle))
|
||||
- Any loops ([`{% for ... %}`](https://docs.djangoproject.com/en/5.2/ref/templates/builtins/#cycle))
|
||||
that the `{% fill %}` tag is part of.
|
||||
- [`Component.get_context_data()`](../../../reference/api#django_components.Component.get_context_data)
|
||||
- [`Component.get_template_data()`](../../../reference/api#django_components.Component.get_template_data)
|
||||
of the component which defined the template (AKA the "root" component).
|
||||
|
||||
!!! warning
|
||||
|
||||
Notice that the component whose `get_context_data()` we use inside
|
||||
Notice that the component whose `get_template_data()` we use inside
|
||||
[`{% fill %}`](../../../reference/template_tags#fill)
|
||||
is NOT the same across the two modes!
|
||||
|
||||
Consider this example:
|
||||
|
||||
```python
|
||||
```djc_py
|
||||
class Outer(Component):
|
||||
template = \"\"\"
|
||||
template = """
|
||||
<div>
|
||||
{% component "inner" %}
|
||||
{% fill "content" %}
|
||||
|
@ -95,20 +90,20 @@ This has two modes:
|
|||
{% endfill %}
|
||||
{% endcomponent %}
|
||||
</div>
|
||||
\"\"\"
|
||||
"""
|
||||
```
|
||||
|
||||
- `"django"` - `my_var` has access to data from `get_context_data()` of both `Inner` and `Outer`.
|
||||
- `"django"` - `my_var` has access to data from `get_template_data()` of both `Inner` and `Outer`.
|
||||
If there are variables defined in both, then `Inner` overshadows `Outer`.
|
||||
|
||||
- `"isolated"` - `my_var` has access to data from `get_context_data()` of ONLY `Outer`.
|
||||
- `"isolated"` - `my_var` has access to data from `get_template_data()` of ONLY `Outer`.
|
||||
|
||||
|
||||
### Example "django"
|
||||
|
||||
Given this template:
|
||||
|
||||
```python
|
||||
```djc_py
|
||||
@register("root_comp")
|
||||
class RootComp(Component):
|
||||
template = """
|
||||
|
@ -120,11 +115,11 @@ class RootComp(Component):
|
|||
{% endwith %}
|
||||
"""
|
||||
|
||||
def get_context_data(self):
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return { "my_var": 123 }
|
||||
```
|
||||
|
||||
Then if [`get_context_data()`](../../../reference/api#django_components.Component.get_context_data)
|
||||
Then if [`get_template_data()`](../../../reference/api#django_components.Component.get_template_data)
|
||||
of the component `"my_comp"` returns following data:
|
||||
|
||||
```py
|
||||
|
@ -148,7 +143,7 @@ all the data defined in the outer layers, like the `{% with %}` tag.
|
|||
|
||||
Given this template:
|
||||
|
||||
```python
|
||||
```djc_py
|
||||
class RootComp(Component):
|
||||
template = """
|
||||
{% with cheese="feta" %}
|
||||
|
@ -159,11 +154,11 @@ class RootComp(Component):
|
|||
{% endwith %}
|
||||
"""
|
||||
|
||||
def get_context_data(self):
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return { "my_var": 123 }
|
||||
```
|
||||
|
||||
Then if [`get_context_data()`](../../../reference/api#django_components.Component.get_context_data)
|
||||
Then if [`get_template_data()`](../../../reference/api#django_components.Component.get_template_data)
|
||||
of the component `"my_comp"` returns following data:
|
||||
|
||||
```py
|
||||
|
@ -177,10 +172,10 @@ Then the template will be rendered as:
|
|||
# cheese
|
||||
```
|
||||
|
||||
Because variables `"my_var"` and `"cheese"` are searched only inside `RootComponent.get_context_data()`.
|
||||
Because variables `"my_var"` and `"cheese"` are searched only inside `RootComponent.get_template_data()`.
|
||||
But since `"cheese"` is not defined there, it's empty.
|
||||
|
||||
!!! info
|
||||
|
||||
Notice that the variables defined with the [`{% with %}`](https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#with)
|
||||
Notice that the variables defined with the [`{% with %}`](https://docs.djangoproject.com/en/5.2/ref/templates/builtins/#with)
|
||||
tag are ignored inside the [`{% fill %}`](../../../reference/template_tags#fill) tag with the `"isolated"` mode.
|
|
@ -1,9 +1,6 @@
|
|||
---
|
||||
title: Authoring component libraries
|
||||
weight: 8
|
||||
---
|
||||
You can publish and share your components for others to use. Below you will find the steps to do so.
|
||||
|
||||
You can publish and share your components for others to use. Here are the steps to do so:
|
||||
For live examples, see the [Community examples](../../overview/community.md#community-examples).
|
||||
|
||||
## Writing component libraries
|
||||
|
||||
|
@ -26,13 +23,13 @@ You can publish and share your components for others to use. Here are the steps
|
|||
|-- mytags.py
|
||||
```
|
||||
|
||||
2. Create custom [`Library`](https://docs.djangoproject.com/en/5.1/howto/custom-template-tags/#how-to-create-custom-template-tags-and-filters)
|
||||
2. Create custom [`Library`](https://docs.djangoproject.com/en/5.2/howto/custom-template-tags/#how-to-create-custom-template-tags-and-filters)
|
||||
and [`ComponentRegistry`](django_components.component_registry.ComponentRegistry) instances in `mytags.py`
|
||||
|
||||
This will be the entrypoint for using the components inside Django templates.
|
||||
|
||||
Remember that Django requires the [`Library`](https://docs.djangoproject.com/en/5.1/howto/custom-template-tags/#how-to-create-custom-template-tags-and-filters)
|
||||
instance to be accessible under the `register` variable ([See Django docs](https://docs.djangoproject.com/en/dev/howto/custom-template-tags)):
|
||||
Remember that Django requires the [`Library`](https://docs.djangoproject.com/en/5.2/howto/custom-template-tags/#how-to-create-custom-template-tags-and-filters)
|
||||
instance to be accessible under the `register` variable ([See Django docs](https://docs.djangoproject.com/en/5.2/howto/custom-template-tags)):
|
||||
|
||||
```py
|
||||
from django.template import Library
|
||||
|
@ -103,36 +100,31 @@ You can publish and share your components for others to use. Here are the steps
|
|||
|
||||
It's also a good idea to have a common prefix for your components, so they can be easily distinguished from users' components. In the example below, we use the prefix `my_` / `My`.
|
||||
|
||||
```py
|
||||
from typing import Dict, NotRequired, Optional, Tuple, TypedDict
|
||||
|
||||
from django_components import Component, SlotFunc, register, types
|
||||
```djc_py
|
||||
from typing import NamedTuple, Optional
|
||||
from django_components import Component, SlotInput, register, types
|
||||
|
||||
from myapp.templatetags.mytags import comp_registry
|
||||
|
||||
# Define the types
|
||||
class EmptyDict(TypedDict):
|
||||
pass
|
||||
|
||||
type MyMenuArgs = Tuple[int, str]
|
||||
|
||||
class MyMenuSlots(TypedDict):
|
||||
default: NotRequired[Optional[SlotFunc[EmptyDict]]]
|
||||
|
||||
class MyMenuProps(TypedDict):
|
||||
vertical: NotRequired[bool]
|
||||
klass: NotRequired[str]
|
||||
style: NotRequired[str]
|
||||
|
||||
# Define the component
|
||||
# NOTE: Don't forget to set the `registry`!
|
||||
@register("my_menu", registry=comp_registry)
|
||||
class MyMenu(Component[MyMenuArgs, MyMenuProps, MyMenuSlots, Any, Any, Any]):
|
||||
def get_context_data(
|
||||
self,
|
||||
*args,
|
||||
attrs: Optional[Dict] = None,
|
||||
):
|
||||
class MyMenu(Component):
|
||||
# Define the types
|
||||
class Args(NamedTuple):
|
||||
size: int
|
||||
text: str
|
||||
|
||||
class Kwargs(NamedTuple):
|
||||
vertical: Optional[bool] = None
|
||||
klass: Optional[str] = None
|
||||
style: Optional[str] = None
|
||||
|
||||
class Slots(NamedTuple):
|
||||
default: Optional[SlotInput] = None
|
||||
|
||||
def get_template_data(self, args: Args, kwargs: Kwargs, slots: Slots, context: Context):
|
||||
attrs = ...
|
||||
return {
|
||||
"attrs": attrs,
|
||||
}
|
||||
|
@ -156,7 +148,7 @@ You can publish and share your components for others to use. Here are the steps
|
|||
|
||||
Since you, as the library author, are not in control of the file system, it is recommended to load the components manually.
|
||||
|
||||
We recommend doing this in the [`AppConfig.ready()`](https://docs.djangoproject.com/en/5.1/ref/applications/#django.apps.AppConfig.ready)
|
||||
We recommend doing this in the [`AppConfig.ready()`](https://docs.djangoproject.com/en/5.2/ref/applications/#django.apps.AppConfig.ready)
|
||||
hook of your `apps.py`:
|
||||
|
||||
```py
|
||||
|
@ -178,7 +170,7 @@ You can publish and share your components for others to use. Here are the steps
|
|||
```
|
||||
|
||||
Note that you can also include any other startup logic within
|
||||
[`AppConfig.ready()`](https://docs.djangoproject.com/en/5.1/ref/applications/#django.apps.AppConfig.ready).
|
||||
[`AppConfig.ready()`](https://docs.djangoproject.com/en/5.2/ref/applications/#django.apps.AppConfig.ready).
|
||||
|
||||
And that's it! The next step is to publish it.
|
||||
|
||||
|
@ -193,7 +185,7 @@ django_components uses the [`build`](https://build.pypa.io/en/stable/) utility t
|
|||
python -m build --sdist --wheel --outdir dist/ .
|
||||
```
|
||||
|
||||
And to publish to PyPI, you can use [`twine`](https://docs.djangoproject.com/en/5.1/ref/applications/#django.apps.AppConfig.ready)
|
||||
And to publish to PyPI, you can use [`twine`](https://docs.djangoproject.com/en/5.2/ref/applications/#django.apps.AppConfig.ready)
|
||||
([See Python user guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives))
|
||||
|
||||
```bash
|
||||
|
@ -227,7 +219,7 @@ After the package has been published, all that remains is to install it in other
|
|||
]
|
||||
```
|
||||
|
||||
3. Optionally add the template tags to the [`builtins`](https://docs.djangoproject.com/en/5.1/topics/templates/#django.template.backends.django.DjangoTemplates),
|
||||
3. Optionally add the template tags to the [`builtins`](https://docs.djangoproject.com/en/5.2/topics/templates/#django.template.backends.django.DjangoTemplates),
|
||||
so you don't have to call `{% load mytags %}` in every template:
|
||||
|
||||
```python
|
|
@ -1,8 +1,3 @@
|
|||
---
|
||||
title: Registering components
|
||||
weight: 5
|
||||
---
|
||||
|
||||
In previous examples you could repeatedly see us using `@register()` to "register"
|
||||
the components. In this section we dive deeper into what it actually means and how you can
|
||||
manage (add or remove) components.
|
||||
|
@ -14,12 +9,12 @@ from django_components import Component, register
|
|||
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_name = "template.html"
|
||||
template_file = "template.html"
|
||||
|
||||
# This component takes one parameter, a date string to show in the template
|
||||
def get_context_data(self, date):
|
||||
def get_template_data(self, args, kwargs, slots, context):
|
||||
return {
|
||||
"date": date,
|
||||
"date": kwargs["date"],
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -85,6 +80,9 @@ registry.register("card", CardComponent)
|
|||
registry.all() # {"button": ButtonComponent, "card": CardComponent}
|
||||
registry.get("card") # CardComponent
|
||||
|
||||
# Check if component is registered
|
||||
registry.has("button") # True
|
||||
|
||||
# Unregister single component
|
||||
registry.unregister("card")
|
||||
|
||||
|
@ -127,6 +125,7 @@ NOTE: The Library instance can be accessed under `library` attribute of `Compone
|
|||
When you are creating an instance of `ComponentRegistry`, you can define the components' behavior within the template.
|
||||
|
||||
The registry accepts these settings:
|
||||
|
||||
- `context_behavior`
|
||||
- `tag_formatter`
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue