-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extended public API * Refactored event loop * Refactored parser * Fixed unit tests * Added --dry-run opt * Added total alloc * Added profiler * Fixed driver registration
- Loading branch information
Showing
37 changed files
with
5,951 additions
and
5,410 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package drivers_test | ||
|
||
import ( | ||
"context" | ||
"github.com/MontFerret/ferret/pkg/drivers" | ||
"github.com/MontFerret/ferret/pkg/drivers/cdp" | ||
"testing" | ||
|
||
"github.com/MontFerret/ferret" | ||
) | ||
|
||
var c *ferret.Instance | ||
|
||
func init() { | ||
c = ferret.New() | ||
c.Drivers().Register(cdp.NewDriver(), drivers.AsDefault()) | ||
} | ||
|
||
func Benchmark_Open_CDP(b *testing.B) { | ||
ctx := context.Background() | ||
|
||
p, err := c.Compile(` | ||
LET doc = DOCUMENT("https://www.montferret.dev") | ||
RETURN TRUE | ||
`) | ||
|
||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
for n := 0; n < b.N; n++ { | ||
if _, err := c.Run(ctx, p); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func Benchmark_Navigate_CDP(b *testing.B) { | ||
ctx := context.Background() | ||
|
||
p, err := c.Compile(` | ||
LET doc = DOCUMENT('https://www.theverge.com/tech', { | ||
driver: "cdp", | ||
ignore: { | ||
resources: [ | ||
{ | ||
url: "*", | ||
type: "image" | ||
} | ||
] | ||
} | ||
}) | ||
WAIT_ELEMENT(doc, '.c-compact-river__entry', 5000) | ||
LET articles = ELEMENTS(doc, '.c-entry-box--compact__image-wrapper') | ||
LET links = ( | ||
FOR article IN articles | ||
FILTER article.attributes?.href LIKE 'https://www.theverge.com/*' | ||
RETURN article.attributes.href | ||
) | ||
FOR link IN links | ||
LIMIT 10 | ||
// The Verge has pretty heavy pages, so let's increase the navigation wait time | ||
NAVIGATE(doc, link, 20000) | ||
WAIT_ELEMENT(doc, '.c-entry-content', 15000) | ||
LET texter = ELEMENT(doc, '.c-entry-content') | ||
RETURN texter.innerText | ||
`) | ||
|
||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
for n := 0; n < b.N; n++ { | ||
if _, err := c.Run(ctx, p); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.