mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| a29f64b700 |
7 changed files with 7 additions and 1207 deletions
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"permissions": {
|
|
||||||
"allow": [
|
|
||||||
"Bash(TestDropWhile\"\ngo test -bench=\"BenchmarkTakeWhile)",
|
|
||||||
"Bash(gh pr create:*)",
|
|
||||||
"Bash(TestTranspose)",
|
|
||||||
"Bash(TestUnzip)",
|
|
||||||
"Bash(TestParallelReduce)"
|
|
||||||
],
|
|
||||||
"deny": [],
|
|
||||||
"ask": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -63,3 +63,4 @@ docs/public
|
||||||
.claude
|
.claude
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
bench*txt
|
bench*txt
|
||||||
|
ACTION_PLAN.md
|
||||||
|
|
|
||||||
1189
ACTION_PLAN.md
1189
ACTION_PLAN.md
File diff suppressed because it is too large
Load diff
|
|
@ -80,7 +80,7 @@ func BenchmarkFirst(b *testing.B) {
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
u.First(nums)
|
_, _ = u.First(nums)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ package underscore
|
||||||
// Also known as foldr in Haskell.
|
// Also known as foldr in Haskell.
|
||||||
//
|
//
|
||||||
// Example: FoldRight([]int{1,2,3}, 0, func(n, acc int) int { return n - acc })
|
// Example: FoldRight([]int{1,2,3}, 0, func(n, acc int) int { return n - acc })
|
||||||
// → 1 - (2 - (3 - 0)) = 1 - (2 - 3) = 1 - (-1) = 2
|
//
|
||||||
|
// → 1 - (2 - (3 - 0)) = 1 - (2 - 3) = 1 - (-1) = 2
|
||||||
func FoldRight[T, P any](values []T, acc P, fn func(T, P) P) P {
|
func FoldRight[T, P any](values []T, acc P, fn func(T, P) P) P {
|
||||||
for i := len(values) - 1; i >= 0; i-- {
|
for i := len(values) - 1; i >= 0; i-- {
|
||||||
acc = fn(values[i], acc)
|
acc = fn(values[i], acc)
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ func BenchmarkParallelMap(b *testing.B) {
|
||||||
b.Run(fmt.Sprintf("workers=%d", workers), func(b *testing.B) {
|
b.Run(fmt.Sprintf("workers=%d", workers), func(b *testing.B) {
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
u.ParallelMap(ctx, data, workers, func(_ context.Context, n int) (int, error) {
|
_, _ = u.ParallelMap(ctx, data, workers, func(_ context.Context, n int) (int, error) {
|
||||||
return n * 2, nil
|
return n * 2, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ func BenchmarkMapVsParallelMap(b *testing.B) {
|
||||||
|
|
||||||
b.Run("ParallelMap", func(b *testing.B) {
|
b.Run("ParallelMap", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
u.ParallelMap(ctx, data, 0, func(_ context.Context, n int) (int, error) {
|
_, _ = u.ParallelMap(ctx, data, 0, func(_ context.Context, n int) (int, error) {
|
||||||
return n * 2, nil
|
return n * 2, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ func BenchmarkParallelReduce(b *testing.B) {
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
u.ParallelReduce(ctx, nums, 4, func(ctx context.Context, n int, acc int) (int, error) {
|
_, _ = u.ParallelReduce(ctx, nums, 4, func(ctx context.Context, n int, acc int) (int, error) {
|
||||||
return n + acc, nil
|
return n + acc, nil
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue