test: полностью удалён блок генерации и теста Go из bench_heavy.py

This commit is contained in:
“Naeel”
2026-05-02 14:24:44 +04:00
parent 9a23a03fc8
commit f527aa1e54
-300
View File
@@ -634,306 +634,6 @@ PERL_CODE = r"""sub {
}
"""
GO_CODE = r"""package main
import (
"encoding/json"
"fmt"
"math"
"math/rand"
"net/http"
"sort"
"strings"
"time"
)
func sieveGo(limit int) []int {
s := make([]bool, limit+1)
for i := range s { s[i] = true }
s[0], s[1] = false, false
for i := 2; i*i <= limit; i++ {
if s[i] { for j := i * i; j <= limit; j += i { s[j] = false } }
}
primes := []int{}
for i := 2; i <= limit; i++ { if s[i] { primes = append(primes, i) } }
return primes
}
func fibGo(n int) int64 {
if n <= 1 { return int64(n) }
a, b := int64(0), int64(1)
for i := 2; i <= n; i++ { a, b = b, a+b }
return b
}
func matMulGo(a, b [20][20]float64) [20][20]float64 {
var c [20][20]float64
for i := 0; i < 20; i++ {
for k := 0; k < 20; k++ {
for j := 0; j < 20; j++ { c[i][j] += a[i][k] * b[k][j] }
}
}
return c
}
func makeMatGo(seed float64) [20][20]float64 {
var m [20][20]float64
for i := 0; i < 20; i++ {
for j := 0; j < 20; j++ {
m[i][j] = math.Mod(float64(i*20+j)+seed, 17)*0.1 + 1.0
}
}
return m
}
func shellSortGo(arr []int) []int {
a := make([]int, len(arr)); copy(a, arr)
for gap := len(a) / 2; gap > 0; gap /= 2 {
for i := gap; i < len(a); i++ {
tmp := a[i]; j := i
for j >= gap && a[j-gap] > tmp { a[j] = a[j-gap]; j -= gap }
a[j] = tmp
}
}
return a
}
func quickSortGo(arr []int) []int {
a := make([]int, len(arr)); copy(a, arr)
sort.Ints(a)
return a
}
func polyEvalGo(coeffs []float64, x float64) float64 {
result, power := 0.0, 1.0
for _, c := range coeffs { result += c * power; power *= x }
return result
}
func djb2Go(s string) uint32 {
h := uint32(5381)
for _, c := range s { h = ((h << 5) + h + uint32(c)) & 0x7fffffff }
return h
}
func fnv1aGo(s string) uint32 {
h := uint32(2166136261)
for _, c := range []byte(s) { h ^= uint32(c); h *= 16777619 }
return h
}
func collatzGo(n int) int {
steps := 0
for n != 1 {
if n%2 == 0 { n /= 2 } else { n = 3*n + 1 }
steps++
}
return steps
}
func isPrimeGo(n int) bool {
if n < 2 { return false }
if n == 2 { return true }
if n%2 == 0 { return false }
for d := 3; d*d <= n; d += 2 { if n%d == 0 { return false } }
return true
}
func gcdGo(a, b int) int {
for b != 0 { a, b = b, a%b }
return a
}
func lcmGo(a, b int) int { return a / gcdGo(a, b) * b }
// Горнер для вычисления полинома
func hornerEval(coeffs []float64, x float64) float64 {
result := 0.0
for i := len(coeffs) - 1; i >= 0; i-- { result = result*x + coeffs[i] }
return result
}
// Решето Сундарама
func sundaramSieve(n int) []int {
limit := (n - 2) / 2
s := make([]bool, limit+1)
for i := 1; i <= limit; i++ {
for j := i; i+j+2*i*j <= limit; j++ { s[i+j+2*i*j] = true }
}
primes := []int{2}
for i := 1; i <= limit; i++ { if !s[i] { primes = append(primes, 2*i+1) } }
return primes
}
// Простые числа через Miller-Rabin (детерминированный для малых n)
func millerRabinGo(n int) bool {
if n < 2 { return false }
if n == 2 || n == 3 || n == 5 || n == 7 { return true }
if n%2 == 0 { return false }
d, r := n-1, 0
for d%2 == 0 { d /= 2; r++ }
witnesses := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}
for _, a := range witnesses {
if a >= n { continue }
x := modPowGo(a, d, n)
if x == 1 || x == n-1 { continue }
cont := false
for _ = range make([]struct{}, r-1) {
x = modPowGo(x, 2, n)
if x == n-1 { cont = true; break }
}
if !cont { return false }
}
return true
}
func modPowGo(base, exp, mod int) int {
result := 1; base %= mod
for exp > 0 {
if exp%2 == 1 { result = result * base % mod }
exp /= 2; base = base * base % mod
}
return result
}
// Числа Люка
func lucasGo(n int) int64 {
if n == 0 { return 2 }
if n == 1 { return 1 }
a, b := int64(2), int64(1)
for i := 2; i <= n; i++ { a, b = b, a+b }
return b
}
// Цифровая сумма
func digitSumGo(n int) int {
s := 0
for n > 0 { s += n % 10; n /= 10 }
return s
}
func Handler(w http.ResponseWriter, r *http.Request) {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
// Random delay 300ms-1800ms
delayMs := 300 + rng.Intn(1500)
time.Sleep(time.Duration(delayMs) * time.Millisecond)
// Phase 1: Sieve of Eratosthenes up to 3000
primes := sieveGo(3000)
primeSum := 0
for _, p := range primes { primeSum += p }
time.Sleep(time.Duration(50+rng.Intn(200)) * time.Millisecond)
// Phase 2: Sundaram sieve cross-check
primes2 := sundaramSieve(3000)
_ = primes2
time.Sleep(time.Duration(30+rng.Intn(150)) * time.Millisecond)
// Phase 3: Miller-Rabin for 1000..1200
mrCount := 0
for n := 1000; n <= 1200; n++ { if millerRabinGo(n) { mrCount++ } }
time.Sleep(time.Duration(20+rng.Intn(100)) * time.Millisecond)
// Phase 4: Fibonacci + Lucas + digit sums
type entry struct{ N int; Fib, Lucas int64; DigSum int }
entries := []entry{}
for n := 20; n <= 60; n += 5 {
f := fibGo(n); l := lucasGo(n)
entries = append(entries, entry{n, f, l, digitSumGo(int(f % 1000000))})
}
time.Sleep(time.Duration(30+rng.Intn(150)) * time.Millisecond)
// Phase 5: Matrix multiply 20x20
A := makeMatGo(3.0); B := makeMatGo(7.0)
C := matMulGo(A, B)
matSum := 0.0
for _, row := range C { for _, v := range row { matSum += v } }
time.Sleep(time.Duration(20+rng.Intn(100)) * time.Millisecond)
// Phase 6: Shell sort + stdlib sort 800 elements, compare
arr := make([]int, 800)
for i := range arr { arr[i] = rng.Intn(10000) }
shellSorted := shellSortGo(arr)
quickSorted := quickSortGo(arr)
sortMatch := true
for i := range shellSorted { if shellSorted[i] != quickSorted[i] { sortMatch = false; break } }
time.Sleep(time.Duration(10+rng.Intn(80)) * time.Millisecond)
// Phase 7: Polynomial evaluation (Horner vs direct)
coeffs := []float64{1, -3, 2, 5, -1, 4, -2, 1, 3, -1, 2, 1, -3, 2, 5, -1, 3, -2, 1, 4}
polyMax, hornerMax := math.Inf(-1), math.Inf(-1)
for i := -80; i <= 80; i++ {
x := float64(i) * 0.1
if v := polyEvalGo(coeffs, x); v > polyMax { polyMax = v }
if v := hornerEval(coeffs, x); v > hornerMax { hornerMax = v }
}
time.Sleep(time.Duration(10+rng.Intn(60)) * time.Millisecond)
// Phase 8: DJB2 + FNV1a hash chains 500 iterations
hDJB := djb2Go("bench-go-start")
hFNV := fnv1aGo("bench-go-start")
for i := 0; i < 500; i++ {
hDJB = djb2Go(fmt.Sprintf("%d", hDJB))
hFNV = fnv1aGo(fmt.Sprintf("%d", hFNV))
}
time.Sleep(time.Duration(10+rng.Intn(50)) * time.Millisecond)
// Phase 9: Collatz max steps for 1..500
collatzMax, collatzN := 0, 0
for n := 1; n <= 500; n++ {
if s := collatzGo(n); s > collatzMax { collatzMax = s; collatzN = n }
}
// Phase 10: GCD/LCM table for first 20 primes
gcdSum, lcmMod := 0, 1
for i := 0; i < 20 && i < len(primes)-1; i++ {
gcdSum += gcdGo(primes[i], primes[i+1])
lcmMod = lcmGo(lcmMod, primes[i]) % 1000000007
}
time.Sleep(time.Duration(10+rng.Intn(40)) * time.Millisecond)
// Phase 11: Twin primes and cousin primes
twins, cousins := 0, 0
for i := 0; i < len(primes)-1; i++ {
diff := primes[i+1] - primes[i]
if diff == 2 { twins++ }
if diff == 4 { cousins++ }
}
// Phase 12: String operations — build prime list string and count digits
var sb strings.Builder
for i, p := range primes { if i >= 100 { break }; fmt.Fprintf(&sb, "%d,", p) }
primeStr := sb.String()
digitCount := 0
for _, c := range primeStr { if c >= '0' && c <= '9' { digitCount++ } }
result := map[string]interface{}{
"language": "go",
"delay_ms": delayMs,
"prime_count": len(primes),
"prime_sum": primeSum,
"mr_count": mrCount,
"fib55": entries[7].Fib,
"lucas55": entries[7].Lucas,
"mat_sum": math.Round(matSum*10000) / 10000,
"sort_match": sortMatch,
"poly_max": math.Round(polyMax*10000) / 10000,
"horner_max": math.Round(hornerMax*10000) / 10000,
"djb2_final": hDJB,
"fnv1a_final": hFNV,
"collatz_max": collatzMax,
"collatz_n": collatzN,
"twin_primes": twins,
"cousin_primes": cousins,
"gcd_sum": gcdSum,
"lcm_mod": lcmMod,
"digit_count": digitCount,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(result)
}
"""
# ── Python ────────────────────────────────────────────────────────────────────
PYTHON_CODE = r"""import time