File: test_benchmarks_http_writer.py

package info (click to toggle)
python-aiohttp 3.11.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,156 kB
  • sloc: python: 51,898; ansic: 20,843; makefile: 395; javascript: 31; sh: 3
file content (33 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""codspeed benchmarks for http writer."""

from multidict import CIMultiDict
from pytest_codspeed import BenchmarkFixture

from aiohttp import hdrs
from aiohttp.http_writer import _serialize_headers


def test_serialize_headers(benchmark: BenchmarkFixture) -> None:
    """Benchmark 100 calls to _serialize_headers."""
    status_line = "HTTP/1.1 200 OK"
    headers = CIMultiDict(
        {
            hdrs.CONTENT_TYPE: "text/plain",
            hdrs.CONTENT_LENGTH: "100",
            hdrs.CONNECTION: "keep-alive",
            hdrs.DATE: "Mon, 23 May 2005 22:38:34 GMT",
            hdrs.SERVER: "Test/1.0",
            hdrs.CONTENT_ENCODING: "gzip",
            hdrs.VARY: "Accept-Encoding",
            hdrs.CACHE_CONTROL: "no-cache",
            hdrs.PRAGMA: "no-cache",
            hdrs.EXPIRES: "0",
            hdrs.LAST_MODIFIED: "Mon, 23 May 2005 22:38:34 GMT",
            hdrs.ETAG: "1234567890",
        }
    )

    @benchmark
    def _run() -> None:
        for _ in range(100):
            _serialize_headers(status_line, headers)