-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (30 loc) · 1.02 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
package main
import (
"fmt"
"time"
"github.com/ckshitij/multithread-file-search-utility/config"
file_search "github.com/ckshitij/multithread-file-search-utility/search_file"
)
func GetTimeElapse(callbackFunc func()) {
startTime := time.Now()
callbackFunc()
elapsed := time.Since(startTime)
fmt.Printf("Total time taken to run the function %d ms\n", elapsed.Milliseconds())
}
func executeMultithreadedSearch() {
fs := file_search.NewFileSearchUtility()
fs.Add(1)
go fs.SearchFile(config.GetDirectory(), config.GetFileName())
fs.Wait()
fmt.Printf("executed the multithreaded, found total %d matched files", len(fs.MatchedFiles()))
}
func executeSyncSearch() {
fs := file_search.NewFileSearchUtility()
fs.SyncSearchFile(config.GetDirectory(), config.GetFileName())
fmt.Printf("executed the sync search, found total %d matched files", len(fs.MatchedFiles()))
}
func main() {
// Compare the time difference between sync and multithread search calls.
GetTimeElapse(executeMultithreadedSearch)
GetTimeElapse(executeSyncSearch)
}