make same performance improvements to all sieve commands
This commit is contained in:
@@ -17,7 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
@@ -27,7 +29,10 @@ var divisorsN uint
|
||||
var divisorsE uint
|
||||
|
||||
func divisors(cmd *cobra.Command, args []string) {
|
||||
ch := lib.DivisorsSieve(divisorsN, divisorsE)
|
||||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.DivisorsSieve(divisorsN, divisorsE, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
@@ -38,7 +43,7 @@ func divisors(cmd *cobra.Command, args []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(v)
|
||||
fmt.Fprintln(bufStdout, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
@@ -26,7 +28,10 @@ import (
|
||||
var mobiusN uint
|
||||
|
||||
func mobius(cmd *cobra.Command, args []string) {
|
||||
ch := lib.MobiusSieve(mobiusN)
|
||||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.MobiusSieve(mobiusN, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
@@ -37,7 +42,7 @@ func mobius(cmd *cobra.Command, args []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(v)
|
||||
fmt.Fprintln(bufStdout, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
@@ -27,7 +29,10 @@ var primeOmegaN uint
|
||||
var primeOmegaMul bool
|
||||
|
||||
func primeOmega(cmd *cobra.Command, args []string) {
|
||||
ch := lib.PrimeOmegaSieve(primeOmegaN, primeOmegaMul)
|
||||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.PrimeOmegaSieve(primeOmegaN, primeOmegaMul, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
@@ -38,7 +43,7 @@ func primeOmega(cmd *cobra.Command, args []string) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(v)
|
||||
fmt.Fprintln(bufStdout, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user