seaweed testing, gitea actions
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var BuildTime string
|
||||
|
||||
const ramChunkSize = 100 * 1024 * 1024 // 0.1 GiB
|
||||
|
||||
var (
|
||||
ramMu sync.Mutex
|
||||
ramChunks [][]byte
|
||||
)
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprintln(w, BuildTime)
|
||||
})
|
||||
http.HandleFunc("/ram", func(w http.ResponseWriter, r *http.Request) {
|
||||
chunk := make([]byte, ramChunkSize)
|
||||
for i := range chunk {
|
||||
chunk[i] = 1
|
||||
}
|
||||
ramMu.Lock()
|
||||
ramChunks = append(ramChunks, chunk)
|
||||
total := len(ramChunks)
|
||||
ramMu.Unlock()
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprintf(w, "allocated 0.1 GiB, total held: %.1f GiB (%d chunks)\n", float64(total)*0.1, total)
|
||||
})
|
||||
http.HandleFunc("/cpu", func(w http.ResponseWriter, r *http.Request) {
|
||||
iterations := 1_000_000
|
||||
if n, err := strconv.Atoi(r.URL.Query().Get("n")); err == nil && n > 0 {
|
||||
iterations = n
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
sum := sha256.Sum256([]byte("zerops"))
|
||||
for i := 0; i < iterations; i++ {
|
||||
sum = sha256.Sum256(sum[:])
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = fmt.Fprintf(w, "computed %x in %s (%d iterations)\n", sum, elapsed, iterations)
|
||||
})
|
||||
_ = http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user