aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorhovertank3d <[email protected]>2025-01-17 15:52:03 +0100
committerhovertank3d <[email protected]>2025-01-17 15:52:03 +0100
commitdd4a4aaf8e7cab8e196f7452b8a3f89411cdf742 (patch)
treef8863c1c0c861b0a6ecaffc47053e62b0095324d /main.go
parenta832581ccc15455428721a7893d825112d95cee8 (diff)
downloadlzcnt.space-dd4a4aaf8e7cab8e196f7452b8a3f89411cdf742.tar.xz
lzcnt.space-dd4a4aaf8e7cab8e196f7452b8a3f89411cdf742.zip
initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..7eba79e
--- /dev/null
+++ b/main.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "html/template"
+ "log"
+ "net/http"
+ "os"
+ "sync/atomic"
+
+ "embed"
+)
+
+/*
+#include <stdint.h>
+extern unsigned long int log2lzcnt(unsigned long int);
+*/
+import "C"
+
+//go:embed templates
+var templates embed.FS
+
+func main() {
+ counter := atomic.Uint64{}
+ host := ":8080"
+ if len(os.Args) == 2 {
+ host = os.Args[1]
+ }
+
+ tmpl, err := template.ParseFS(templates, "templates/*.html")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ n := counter.Add(1)
+ payload := struct {
+ Requests uint64
+ Log2lzcnt uint64
+ }{
+ Requests: n,
+ Log2lzcnt: uint64(C.log2lzcnt(C.uint64_t(n))),
+ }
+
+ tmpl.Execute(w, payload)
+ })
+
+ http.ListenAndServe(host, nil)
+}