Created
May 30, 2016 19:18
-
-
Save crhntr/be692f49e3977f4005427a2b564034bc to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"go/scanner" | |
"go/token" | |
"math" | |
"sync" | |
"time" | |
) | |
func main() { | |
fmt.Println("START | END | PASSES | FAILS | TOTAL | TIME ") | |
var wg sync.WaitGroup | |
h := 0 | |
limit := int(math.Pow(2, 16)) | |
size := limit / int(math.Pow(2, 10)) | |
for ; h+size <= limit; h += size { | |
wg.Add(1) | |
go func(a, b int) { | |
defer wg.Done() | |
passCount, failCount := 0, 0 | |
var r rune | |
r += rune(a) | |
//ri := r | |
var i int | |
start := time.Now() | |
var fset *token.FileSet | |
var s scanner.Scanner | |
var src string | |
var file *token.File | |
for i = a; i < b; i++ { | |
src = fmt.Sprintf("%c := 0\n", r) | |
fset = token.NewFileSet() | |
file = fset.AddFile("", fset.Base(), len(src)) | |
s.Init(file, []byte(src), nil /* no error handler */, scanner.ScanComments) | |
for { | |
_, tok, _ := s.Scan() | |
if tok == token.EOF { | |
break | |
} | |
if tok == token.ILLEGAL { | |
failCount++ | |
} else if tok == token.IDENT { | |
passCount++ | |
} | |
} | |
r++ | |
} | |
fmt.Printf(" %8d | %8d | %8d | %8d | %8d | %s \n", a, b, passCount, failCount, b-a, time.Since(start)) | |
}(h, h+size-1) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this after finding that some Unicode characters did not work as valid character tokens. I wanted to use U+2203, the Existential 'THERE EXISTS' character in a private method and go complained. Also I used it to practice using goroutines.