subfinder / research

❄️ Research project for SubFinder core API V2
MIT License
35 stars 8 forks source link

Implement better Result type #2

Closed picatz closed 6 years ago

picatz commented 6 years ago

This is a (work-in-progress) PR that aims to fix https://github.com/subfinder/research/issues/1

codingo commented 6 years ago

Solid work!

Mzack9999 commented 6 years ago

I definitely like this

Ice3man543 commented 6 years ago

Great work.

picatz commented 6 years ago

Going to look over this once more (right now this morning) and then merge the new Result struct. 👍

picatz commented 6 years ago

Before Merging

I'm going to add tests for the Printable(), IsPrintable(), Print(), and JSON() functions that aren't just Examples ( which are actually tests still ).

That way everything has a test and an example.

picatz commented 6 years ago

😂 I love how I just realized the IsPrintable() function I wrote has basically no way for it to return false, ever. Might remove that. The Print()function, I think, is really only useful for debugging at the moment anyway.

It can also be re-worked or added back later when actually needed.

picatz commented 6 years ago

lol

picatz commented 6 years ago

This should solve our problems nicely, I think. https://play.golang.org/p/OwQUoohP2rn

picatz commented 6 years ago

Obviously I'm adding some stuff I feel is missing at this point.

picatz commented 6 years ago

Benchmark Results

Note: 🤷‍♂️ Benchmarks are weird, but sometimes helpful.

goos: darwin
goarch: amd64
BenchmarkResultGetTypeThreadSafe-8                              30000000            56.7 ns/op
BenchmarkResultGetTypeThreadSafeMultiThreaded-8                  5000000           285 ns/op
BenchmarkResultGetType-8                                        2000000000           1.54 ns/op
BenchmarkResultGetTypeMultiThreaded-8                            5000000           311 ns/op
BenchmarkNewResultSingleThreaded-8                              20000000            87.9 ns/op
BenchmarkNewResultMultiThreaded-8                                5000000           309 ns/op
BenchmarkInitializeEmptyResultSingleThreaded-8                  2000000000           0.30 ns/op
BenchmarkInitializeSuccessResultSingleThreaded-8                300000000            4.55 ns/op
BenchmarkInitializeEmptyPointerToResultSingleThreaded-8         500000000            3.05 ns/op
BenchmarkInitializeSuccessPointerToResultSingleThreaded-8       300000000            4.59 ns/op
BenchmarkInitializeEmptyResultMulitThreaded-8                    5000000           311 ns/op
BenchmarkInitializeSuccessResultMulitThreaded-8                  5000000           318 ns/op
BenchmarkInitializeEmptyPointerToResultMulitThreaded-8           5000000           308 ns/op
BenchmarkInitializeSuccessPointerToResultMulitThreaded-8         5000000           313 ns/op
picatz commented 6 years ago

Note: you can test the benchmarks like this:

$ go test -bench=.
picatz commented 6 years ago

We'll see how helpful the benchmarks are. 😂