-
-
Notifications
You must be signed in to change notification settings - Fork 14
add performance test #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fifthsegment
wants to merge
6
commits into
master
Choose a base branch
from
chore-performance-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82517c3
add performance test
fifthsegment 98ec552
add support for rule based filtering
fifthsegment 7fa4d86
add rule handler
fifthsegment 44d5eb8
update rule handler
fifthsegment 17beaee
update rule handler
fifthsegment fb390cd
update rule handler
fifthsegment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| { | ||
| "editor.formatOnSave": true, | ||
| "[svelte]": {"editor.defaultFormatter": "svelte.svelte-vscode"} | ||
| } | ||
| "editor.formatOnSave": true, | ||
| "[svelte]": { | ||
| "editor.defaultFormatter": "svelte.svelte-vscode" | ||
| }, | ||
| "[python]": { | ||
| "editor.defaultFormatter": "ms-python.autopep8" | ||
| }, | ||
| "python.formatting.provider": "none" | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "crypto/tls" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
| "time" | ||
|
|
||
| "github.com/PuerkitoBio/goquery" | ||
| ) | ||
|
|
||
| const numRuns = 3 | ||
|
|
||
| func main() { | ||
| // Set up the proxy | ||
| proxyURL, err := url.Parse("http://guest:password@10.1.0.141:10413") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| httpTransport := &http.Transport{ | ||
| // add proxy credentials | ||
|
|
||
| Proxy: http.ProxyURL(proxyURL), | ||
| TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
| } | ||
| httpClient := &http.Client{ | ||
| Transport: httpTransport, | ||
| } | ||
|
|
||
| // List of websites to visit | ||
| websites := []string{"https://edition.cnn.com", "https://nrk.no", "https://www.reddit.com"} | ||
|
|
||
| for _, website := range websites { | ||
| var totalDuration time.Duration | ||
|
|
||
| for i := 0; i < numRuns; i++ { | ||
| start := time.Now() | ||
|
|
||
| // Fetch the HTML | ||
| resp, err := httpClient.Get(website) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| continue | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| // Parse the HTML | ||
| doc, err := goquery.NewDocumentFromReader(resp.Body) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| continue | ||
| } | ||
|
|
||
| // Find and download assets | ||
| doc.Find("img").Each(func(index int, element *goquery.Selection) { | ||
| src, exists := element.Attr("src") | ||
| if exists { | ||
| _, err := httpClient.Get(src) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| elapsed := time.Since(start) | ||
| totalDuration += elapsed | ||
| } | ||
|
|
||
| // Calculate and print the average time | ||
| averageDuration := totalDuration / numRuns | ||
| fmt.Printf("Average time taken to download assets from %s: %s\n", website, averageDuration) | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import time | ||
| import urllib.request | ||
| from requests_html import HTMLSession | ||
| import time | ||
|
|
||
|
|
||
| def measure_performance(proxy_server_url, test_url): | ||
| """Measures the performance of a proxy server. | ||
|
|
||
| Args: | ||
| proxy_server_url: The URL of the proxy server. | ||
| test_url: The URL of the website to test the proxy server against. | ||
|
|
||
| Returns: | ||
| A tuple of (response_time, status_code). | ||
| """ | ||
| session = HTMLSession() | ||
| proxies = { | ||
| "http": proxy_server_url, | ||
| "https": proxy_server_url, | ||
| } | ||
| session.proxies = proxies | ||
|
|
||
| start_time = time.time() | ||
| try: | ||
| response = session.get(test_url, verify=False) | ||
| response.html.render() # This will download the assets and execute JavaScript | ||
| status_code = response.status_code | ||
| except Exception as e: | ||
| print(f"An error occurred: {e}") | ||
| status_code = None | ||
| finally: | ||
| response_time = time.time() - start_time | ||
|
|
||
| return response_time, status_code | ||
|
|
||
|
|
||
| def main(): | ||
| """Measures the performance of a proxy server and prints the results to the console.""" | ||
|
|
||
| proxy_server_url = "http://guest:password@10.1.0.141:10413" | ||
| test_url = "https://nrk.no" | ||
|
|
||
| response_time, status_code = measure_performance( | ||
| proxy_server_url, test_url) | ||
|
|
||
| print("Response time:", response_time) | ||
| print("Status code:", status_code) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Disabled TLS certificate check