-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (70 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"os"
"github.com/gnana997/billion-rows-challenge/GenerateDataSet"
parallelmmapimplementation "github.com/gnana997/billion-rows-challenge/ParallelMmapImplementation"
simpleprocess "github.com/gnana997/billion-rows-challenge/SimpleProcess"
mmapimplementation "github.com/gnana997/billion-rows-challenge/mmapImplementation"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{Use: "app"}
var filePath string
var rows int
createCmd := &cobra.Command{
Use: "create",
Short: "Create a file",
Run: func(cmd *cobra.Command, args []string) {
if rows == 0 {
fmt.Println("Please provide number of rows to be generated --rows")
os.Exit(1)
}
if filePath == "" {
fmt.Println("Please provide a file path using --file")
os.Exit(1)
}
GenerateDataSet.GenerateDataSet(rows, filePath)
},
}
createCmd.Flags().StringVarP(&filePath, "file", "f", "", "Name of the file to create")
createCmd.Flags().IntVarP(&rows, "rows", "c", 0, "Content to write to the file")
readCmd := &cobra.Command{
Use: "simple-process",
Short: "Read a file and process it sequentially",
Run: func(cmd *cobra.Command, args []string) {
if filePath == "" {
fmt.Println("Please provide a file name using --file")
os.Exit(1)
}
simpleprocess.SimplProcessFunc(filePath)
},
}
readCmd.Flags().StringVarP(&filePath, "file", "f", "", "Name of the file to read")
mmapCmd := &cobra.Command{
Use: "use-basic-mmap",
Short: "Read a file and load it into mmap in memory and process it sequentially",
Run: func(cmd *cobra.Command, args []string) {
if filePath == "" {
fmt.Println("Please provide a file name using --file")
os.Exit(1)
}
mmapimplementation.MmapImplementationFunc(filePath)
},
}
mmapCmd.Flags().StringVarP(&filePath, "file", "f", "", "Name of the file to read")
paralleMmapCmd := &cobra.Command{
Use: "use-parallel-mmap",
Short: "Read a file and load it into mmap in memory and process it sequentially",
Run: func(cmd *cobra.Command, args []string) {
if filePath == "" {
fmt.Println("Please provide a file name using --file")
os.Exit(1)
}
parallelmmapimplementation.ParallelMmapImplementation(filePath)
},
}
paralleMmapCmd.Flags().StringVarP(&filePath, "file", "f", "", "Name of the file to read")
rootCmd.AddCommand(createCmd, readCmd, mmapCmd, paralleMmapCmd)
rootCmd.Execute()
}