diff --git a/count/Cargo.lock b/count/Cargo.lock index 46ec825..60bae37 100644 --- a/count/Cargo.lock +++ b/count/Cargo.lock @@ -219,6 +219,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" name = "count" version = "0.1.0" dependencies = [ + "http", "poem", "poem-openapi", "tokio", diff --git a/count/Cargo.toml b/count/Cargo.toml index 05a444f..63d0408 100644 --- a/count/Cargo.toml +++ b/count/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +http = "1.2.0" poem = "3" poem-openapi = { version = "5", features = ["swagger-ui"] } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/count/src/main.rs b/count/src/main.rs index da13747..6b3d99f 100644 --- a/count/src/main.rs +++ b/count/src/main.rs @@ -1,9 +1,10 @@ use std::sync::atomic::{AtomicU32, Ordering}; -use poem_openapi::payload::PlainText; +use poem_openapi::payload::{Response, PlainText}; use poem_openapi::{OpenApi, OpenApiService}; -use poem::{Route, Server}; +use poem::{EndpointExt, Route, Server}; use poem::listener::TcpListener; +use poem::middleware::Cors; pub struct CounterApi { counter: AtomicU32, @@ -18,6 +19,7 @@ impl CounterApi { } } + #[oai(path = "/next", method = "get")] pub async fn next(&self) -> PlainText { let next = self.counter.fetch_add(1, Ordering::Relaxed); @@ -31,6 +33,7 @@ impl CounterApi { PlainText(format!("{{\"count\":{next}}}")) } + } #[tokio::main] @@ -38,7 +41,7 @@ async fn main() { let api_service = OpenApiService::new(CounterApi::new(), "counter", "1.0").server("http://localhost:9000"); let ui = api_service.swagger_ui(); - let app = Route::new().nest("/", api_service).nest("/docs", ui); + let app = Route::new().nest("/", api_service).nest("/docs", ui).with(Cors::new()); Server::new(TcpListener::bind("127.0.0.1:9000")) .run(app) diff --git a/htmx/count.html b/htmx/count.html new file mode 100644 index 0000000..b53c42b --- /dev/null +++ b/htmx/count.html @@ -0,0 +1,11 @@ + + + + htmx test + + + + +

Count:

+ + diff --git a/htmx/index.html b/htmx/index.html index bc64b76..8efaee7 100644 --- a/htmx/index.html +++ b/htmx/index.html @@ -5,7 +5,7 @@ - +
diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..33bcc12 --- /dev/null +++ b/readme.md @@ -0,0 +1,59 @@ + +# static test + +loads "card" from static data, serve with serve.py and test htmx and svelte-build + + +# counter test + +use in console from `htmx/count.html` or `svelte-build/count.html` + +```js + +(async rounds => { + const sleep = () => new Promise(resolve => setTimeout(resolve)); + + const check = async () => { + document.getElementById("nextbtn").click(); + await sleep(); + }; + + const t0 = performance.now(); + for (let i = 0; i < rounds; i++) await check(); + const t1 = performance.now(); + console.log(`took ${t1 - t0} milliseconds`); +})(1000); + +``` + + +results from m2 mac mini: + +``` + +CHROME: + +article loader + +svelte: 5169ms (subseq iters - 5402ms, 5491ms, 5552ms) +htmx: 5078ms (subseq iters - 5510ms, 5542ms, 5588ms) + + +counter test + +svelte: 5160 ms +htmx: 5319 ms + +FIREFOX: + +article loader + +svelte: 5819ms (subseq iters - 8753ms, 13350ms, 17690ms) +htmx: 5038ms (subseq iters - 5158ms, 5292ms, 5475ms) + +couter test + +svelte: 5274 ms +htmx: 4979ms + +``` diff --git a/svelte/my-app/src/routes/+page.svelte b/svelte/my-app/src/routes/+page.svelte index fb204f4..1a2203f 100644 --- a/svelte/my-app/src/routes/+page.svelte +++ b/svelte/my-app/src/routes/+page.svelte @@ -16,7 +16,7 @@
- + {#each cards as card}
diff --git a/svelte/my-app/src/routes/count/+page.svelte b/svelte/my-app/src/routes/count/+page.svelte new file mode 100644 index 0000000..0699823 --- /dev/null +++ b/svelte/my-app/src/routes/count/+page.svelte @@ -0,0 +1,23 @@ + + +
+ + + + {#if count} +

Count: {count}

+ {/if} + +