feat(core): implement core MEV bot functionality with market scanning and Uniswap V3 pricing
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
56
vendor/github.com/consensys/gnark-crypto/internal/parallel/execute.go
generated
vendored
Normal file
56
vendor/github.com/consensys/gnark-crypto/internal/parallel/execute.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package parallel
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Execute process in parallel the work function
|
||||
func Execute(nbIterations int, work func(int, int), maxCpus ...int) {
|
||||
|
||||
nbTasks := runtime.NumCPU()
|
||||
if len(maxCpus) == 1 {
|
||||
nbTasks = maxCpus[0]
|
||||
if nbTasks < 1 {
|
||||
nbTasks = 1
|
||||
} else if nbTasks > 512 {
|
||||
nbTasks = 512
|
||||
}
|
||||
}
|
||||
|
||||
if nbTasks == 1 {
|
||||
// no go routines
|
||||
work(0, nbIterations)
|
||||
return
|
||||
}
|
||||
|
||||
nbIterationsPerCpus := nbIterations / nbTasks
|
||||
|
||||
// more CPUs than tasks: a CPU will work on exactly one iteration
|
||||
if nbIterationsPerCpus < 1 {
|
||||
nbIterationsPerCpus = 1
|
||||
nbTasks = nbIterations
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
extraTasks := nbIterations - (nbTasks * nbIterationsPerCpus)
|
||||
extraTasksOffset := 0
|
||||
|
||||
for i := 0; i < nbTasks; i++ {
|
||||
wg.Add(1)
|
||||
_start := i*nbIterationsPerCpus + extraTasksOffset
|
||||
_end := _start + nbIterationsPerCpus
|
||||
if extraTasks > 0 {
|
||||
_end++
|
||||
extraTasks--
|
||||
extraTasksOffset++
|
||||
}
|
||||
go func() {
|
||||
work(_start, _end)
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user