forked from vikesh-raj/go-sentencepiece-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refined implementation and fixed perf issue
- Loading branch information
Showing
5 changed files
with
115 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"sync" | ||
"time" | ||
|
||
"github.com/susanhuhu/go-sentencepiece-encoder/sentencepiece" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Println("Please provide an integer argument.") | ||
return | ||
} | ||
|
||
// Get the argument from the command-line | ||
arg := os.Args[1] | ||
|
||
// Parse the argument as an integer | ||
count, _ := strconv.Atoi(arg) | ||
|
||
sp, err := sentencepiece.NewSentencepieceFromFile("../sentencepiece/test_data/spm1.model", false) | ||
if err != nil { | ||
panic(fmt.Sprintf("Unable to create sentencepiece: %v", err)) | ||
} | ||
|
||
// Create a wait group to wait for all goroutines to finish | ||
var wg sync.WaitGroup | ||
|
||
// Set the number of goroutines to wait for | ||
wg.Add(count) | ||
|
||
data := "" | ||
// Launch count goroutines | ||
for i := 0; i < count; i++ { | ||
go func(i int) { | ||
for j := 0; j < 1; j++ { | ||
// Call the method | ||
start := time.Now() | ||
sp.TokenizeToOffsets(data) | ||
latency := time.Since(start) | ||
fmt.Printf("%d:%d: tokenize %d data used %v \n", i, j, len(data), latency) | ||
} | ||
// Notify the wait group that this goroutine has finished | ||
wg.Done() | ||
}(i) | ||
} | ||
|
||
// Wait for all goroutines to finish | ||
wg.Wait() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters