-
-
Save piotrkubisa/03e04aaa8a4c5992189c556596f12689 to your computer and use it in GitHub Desktop.
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
{ | |
"resource": "/{proxy+}", | |
"path": "/hello/world", | |
"httpMethod": "POST", | |
"headers": { | |
"Accept": "*/*", | |
"Accept-Encoding": "gzip, deflate", | |
"cache-control": "no-cache", | |
"CloudFront-Forwarded-Proto": "https", | |
"CloudFront-Is-Desktop-Viewer": "true", | |
"CloudFront-Is-Mobile-Viewer": "false", | |
"CloudFront-Is-SmartTV-Viewer": "false", | |
"CloudFront-Is-Tablet-Viewer": "false", | |
"CloudFront-Viewer-Country": "US", | |
"Content-Type": "application/json", | |
"headerName": "headerValue", | |
"Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com", | |
"Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f", | |
"User-Agent": "PostmanRuntime/2.4.5", | |
"Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)", | |
"X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==", | |
"X-Forwarded-For": "54.240.196.186, 54.182.214.83", | |
"X-Forwarded-Port": "443", | |
"X-Forwarded-Proto": "https" | |
}, | |
"multiValueHeaders": { | |
"Accept": [ | |
"*/*" | |
], | |
"Accept-Encoding": [ | |
"gzip, deflate" | |
], | |
"cache-control": [ | |
"no-cache" | |
], | |
"CloudFront-Forwarded-Proto": [ | |
"https" | |
], | |
"CloudFront-Is-Desktop-Viewer": [ | |
"true" | |
], | |
"CloudFront-Is-Mobile-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-SmartTV-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-Tablet-Viewer": [ | |
"false" | |
], | |
"CloudFront-Viewer-Country": [ | |
"US" | |
], | |
"Content-Type": [ | |
"application/json" | |
], | |
"headerName": [ | |
"headerValue" | |
], | |
"Host": [ | |
"gy415nuibc.execute-api.us-east-1.amazonaws.com" | |
], | |
"Postman-Token": [ | |
"9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f" | |
], | |
"User-Agent": [ | |
"PostmanRuntime/2.4.5" | |
], | |
"Via": [ | |
"1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)" | |
], | |
"X-Amz-Cf-Id": [ | |
"pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==" | |
], | |
"X-Forwarded-For": [ | |
"54.240.196.186, 54.182.214.83" | |
], | |
"X-Forwarded-Port": [ | |
"443" | |
], | |
"X-Forwarded-Proto": [ | |
"https" | |
] | |
}, | |
"queryStringParameters": { | |
"name": "me" | |
}, | |
"multiValueQueryStringParameters": { | |
"name": [ | |
"me" | |
] | |
}, | |
"pathParameters": { | |
"proxy": "hello/world" | |
}, | |
"stageVariables": { | |
"stageVariableName": "stageVariableValue" | |
}, | |
"requestContext": { | |
"accountId": "12345678912", | |
"resourceId": "roq9wj", | |
"stage": "testStage", | |
"requestId": "deef4878-7910-11e6-8f14-25afc3e9ae33", | |
"identity": { | |
"cognitoIdentityPoolId": "theCognitoIdentityPoolId", | |
"accountId": "theAccountId", | |
"cognitoIdentityId": "theCognitoIdentityId", | |
"caller": "theCaller", | |
"apiKey": "theApiKey", | |
"accessKey": "ANEXAMPLEOFACCESSKEY", | |
"sourceIp": "192.168.196.186", | |
"cognitoAuthenticationType": "theCognitoAuthenticationType", | |
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider", | |
"userArn": "theUserArn", | |
"userAgent": "PostmanRuntime/2.4.5", | |
"user": "theUser" | |
}, | |
"authorizer": { | |
"principalId": "admin", | |
"clientId": 1, | |
"clientName": "Exata" | |
}, | |
"resourcePath": "/{proxy+}", | |
"httpMethod": "POST", | |
"apiId": "gy415nuibc" | |
}, | |
"body": "{\r\n\t\"a\": 1\r\n}" | |
} |
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
package apigo_test | |
import ( | |
"context" | |
"encoding/json" | |
"io/ioutil" | |
"net/http" | |
"testing" | |
"github.com/apex/gateway" | |
"github.com/aws/aws-lambda-go/events" | |
"github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc" | |
"github.com/piotrkubisa/apigo" | |
) | |
func BenchmarkGateway_Serve(b *testing.B) { | |
g := apigo.NewGateway("api.example.com", http.HandlerFunc(helloHandler)) | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
g.Serve(context.TODO(), ev) | |
} | |
} | |
func helloHandler(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "application/json") | |
w.WriteHeader(http.StatusTeapot) | |
w.Write([]byte(`"Hello World"`)) | |
} | |
func BenchmarkApexFunc(b *testing.B) { | |
h := http.HandlerFunc(helloHandler) | |
gServe := func(ctx context.Context, e events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | |
r, err := gateway.NewRequest(ctx, e) | |
if err != nil { | |
return events.APIGatewayProxyResponse{}, err | |
} | |
w := gateway.NewResponse() | |
h.ServeHTTP(w, r) | |
return w.End(), nil | |
} | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
gServe(context.TODO(), ev) | |
} | |
} | |
func BenchmarkLambdaProxy(b *testing.B) { | |
g := handlerfunc.New(helloHandler) | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
g.Proxy(ev) | |
} | |
} |
NOTE: Outdated. Please, scroll down.
$ go test -benchmem -run=^$ github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc -bench '^(BenchmarkLambdaProxy)$' -count 5
goos: linux
goarch: amd64
pkg: github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc
BenchmarkLambdaProxy-4 100000 17201 ns/op 7436 B/op 74 allocs/op
BenchmarkLambdaProxy-4 100000 17188 ns/op 7438 B/op 74 allocs/op
BenchmarkLambdaProxy-4 100000 16925 ns/op 7436 B/op 74 allocs/op
BenchmarkLambdaProxy-4 100000 16845 ns/op 7436 B/op 74 allocs/op
BenchmarkLambdaProxy-4 100000 16113 ns/op 7437 B/op 74 allocs/op
PASS
ok github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc 9.164s
$ go test -benchmem -run=^$ github.com/piotrkubisa/apigo -bench '^(BenchmarkGateway_Serve)$' -count 5
goos: linux
goarch: amd64
pkg: github.com/piotrkubisa/apigo
BenchmarkGateway_Serve-4 200000 10199 ns/op 5686 B/op 59 allocs/op
BenchmarkGateway_Serve-4 200000 9610 ns/op 5688 B/op 59 allocs/op
BenchmarkGateway_Serve-4 200000 9483 ns/op 5687 B/op 59 allocs/op
BenchmarkGateway_Serve-4 200000 9557 ns/op 5687 B/op 59 allocs/op
BenchmarkGateway_Serve-4 200000 9436 ns/op 5686 B/op 59 allocs/op
PASS
ok github.com/piotrkubisa/apigo 10.192s
$ go test -benchmem -run=^$ github.com/apex/gateway -bench '^(BenchmarkApexFunc)$' -count 5
goos: linux
goarch: amd64
pkg: github.com/apex/gateway
BenchmarkApexFunc-4 200000 9389 ns/op 6271 B/op 61 allocs/op
BenchmarkApexFunc-4 200000 9352 ns/op 6272 B/op 61 allocs/op
BenchmarkApexFunc-4 200000 9262 ns/op 6270 B/op 61 allocs/op
BenchmarkApexFunc-4 200000 9421 ns/op 6271 B/op 61 allocs/op
BenchmarkApexFunc-4 200000 11302 ns/op 6271 B/op 61 allocs/op
PASS
ok github.com/apex/gateway 11.283s
$ go test -benchmem -run=^$ github.com/piotrkubisa/apigo -bench '^(BenchmarkGateway_Serve)$' -count 5
goos: linux
goarch: amd64
pkg: github.com/piotrkubisa/apigo
BenchmarkGateway_Serve-4 200000 8771 ns/op 5686 B/op 60 allocs/op
BenchmarkGateway_Serve-4 200000 8578 ns/op 5687 B/op 60 allocs/op
BenchmarkGateway_Serve-4 200000 8622 ns/op 5687 B/op 60 allocs/op
BenchmarkGateway_Serve-4 200000 8594 ns/op 5687 B/op 60 allocs/op
BenchmarkGateway_Serve-4 200000 8745 ns/op 5687 B/op 60 allocs/op
PASS
ok github.com/piotrkubisa/apigo 9.120s
$ go test -benchmem -run=^$ github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc -bench '^(BenchmarkLambdaProxy)$' -v -count 5
goos: linux
goarch: amd64
pkg: github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc
BenchmarkLambdaProxy-4 100000 12659 ns/op 7099 B/op 73 allocs/op
BenchmarkLambdaProxy-4 100000 12615 ns/op 7100 B/op 73 allocs/op
BenchmarkLambdaProxy-4 100000 12697 ns/op 7100 B/op 73 allocs/op
BenchmarkLambdaProxy-4 100000 12726 ns/op 7100 B/op 73 allocs/op
BenchmarkLambdaProxy-4 100000 12602 ns/op 7099 B/op 73 allocs/op
PASS
ok github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc 6.999s
$ go test -benchmem -run=^$ github.com/apex/gateway -bench '^(BenchmarkApexFunc)$' -v -count 5
goos: linux
goarch: amd64
pkg: github.com/apex/gateway
BenchmarkApexFunc-4 200000 11651 ns/op 9182 B/op 65 allocs/op
BenchmarkApexFunc-4 200000 11778 ns/op 9182 B/op 65 allocs/op
BenchmarkApexFunc-4 200000 11481 ns/op 9180 B/op 65 allocs/op
BenchmarkApexFunc-4 200000 11682 ns/op 9182 B/op 65 allocs/op
BenchmarkApexFunc-4 200000 11669 ns/op 9181 B/op 65 allocs/op
PASS
ok github.com/apex/gateway 12.259s
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Use
--count 5
ingo test
.