Last active
January 12, 2026 01:19
-
-
Save cgoldberg/3ebc4dae0eb8eea771ef65dad5d12bc0 to your computer and use it in GitHub Desktop.
Benchmark Selenium script execution: WebDriver Classic vs. BiDi
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| """Benchmark Selenium script execution: WebDriver Classic vs. BiDi""" | |
| import timeit | |
| from selenium import webdriver | |
| NUM = 500 | |
| service = webdriver.ChromeService(executable_path="/usr/bin/chromedriver") | |
| options = webdriver.ChromeOptions() | |
| options.enable_bidi = True | |
| driver = webdriver.Chrome(options=options, service=service) | |
| driver.get("https://example.com") | |
| def execute_classic(): | |
| return driver.execute_script("return document;") | |
| def execute_bidi(): | |
| return driver.script.execute( | |
| "() => { return document; }", | |
| ) | |
| t_classic = timeit.timeit(execute_classic, number=NUM) | |
| print("execute script with WebDriver Classic:") | |
| print(f" - time for {NUM} iterations: {(t_classic * 1000.0):.03f} millisecs") | |
| print(f" - average time per execution: {(t_classic / NUM * 1000.0):.03f} millisecs") | |
| print() | |
| t_bidi = timeit.timeit(execute_bidi, number=NUM) | |
| print("execute script with WebDriver BiDi:") | |
| print(f" - time for {NUM} iterations: {(t_bidi * 1000.0):.03f} millisecs") | |
| print(f" - average time per execution: {(t_bidi / NUM * 1000.0):.03f} millisecs") | |
| print() | |
| print(f"WebDriver Classic is {(t_bidi / t_classic):.2f}X faster than WebDriver BiDi") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment