diff --git a/private/protocol/restjson/build_bench_test.go b/private/protocol/restjson/build_bench_test.go index 31e1d6c04c7..7a8a8c2c382 100644 --- a/private/protocol/restjson/build_bench_test.go +++ b/private/protocol/restjson/build_bench_test.go @@ -3,232 +3,131 @@ package restjson_test import ( - "bytes" - "encoding/json" + "net/http" + "net/http/httptest" + "os" "testing" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/awstesting" - "github.com/aws/aws-sdk-go/private/protocol/rest" + "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/private/protocol/restjson" "github.com/aws/aws-sdk-go/service/elastictranscoder" ) -func BenchmarkRESTJSONBuild_Complex_elastictranscoderCreateJobInput(b *testing.B) { - svc := awstesting.NewClient() - svc.ServiceName = "elastictranscoder" - svc.APIVersion = "2012-09-25" +var ( + elastictranscoderSvc *elastictranscoder.ElasticTranscoder +) - for i := 0; i < b.N; i++ { - r := svc.NewRequest(&request.Operation{Name: "CreateJobInput"}, restjsonBuildParms, nil) - restjson.Build(r) - if r.Error != nil { - b.Fatal("Unexpected error", r.Error) - } - } +func TestMain(m *testing.M) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + })) + + sess := session.Must(session.NewSession(&aws.Config{ + Credentials: credentials.NewStaticCredentials("Key", "Secret", "Token"), + Endpoint: aws.String(server.URL), + S3ForcePathStyle: aws.Bool(true), + DisableSSL: aws.Bool(true), + Region: aws.String(endpoints.UsWest2RegionID), + })) + elastictranscoderSvc = elastictranscoder.New(sess) + + c := m.Run() + server.Close() + os.Exit(c) } -func BenchmarkRESTBuild_Complex_elastictranscoderCreateJobInput(b *testing.B) { - svc := awstesting.NewClient() - svc.ServiceName = "elastictranscoder" - svc.APIVersion = "2012-09-25" +func BenchmarkRESTJSONBuild_Complex_ETCCreateJob(b *testing.B) { + params := elastictranscoderCreateJobInput() - for i := 0; i < b.N; i++ { - r := svc.NewRequest(&request.Operation{Name: "CreateJobInput"}, restjsonBuildParms, nil) - rest.Build(r) - if r.Error != nil { - b.Fatal("Unexpected error", r.Error) - } - } + benchRESTJSONBuild(b, func() *request.Request { + req, _ := elastictranscoderSvc.CreateJobRequest(params) + return req + }) } -func BenchmarkEncodingJSONMarshal_Complex_elastictranscoderCreateJobInput(b *testing.B) { - params := restjsonBuildParms +func BenchmarkRESTJSONBuild_Simple_ETCListJobsByPipeline(b *testing.B) { + params := elastictranscoderListJobsByPipeline() - for i := 0; i < b.N; i++ { - buf := &bytes.Buffer{} - encoder := json.NewEncoder(buf) - if err := encoder.Encode(params); err != nil { - b.Fatal("Unexpected error", err) - } - } + benchRESTJSONBuild(b, func() *request.Request { + req, _ := elastictranscoderSvc.ListJobsByPipelineRequest(params) + return req + }) } -func BenchmarkRESTJSONBuild_Simple_elastictranscoderListJobsByPipeline(b *testing.B) { - svc := awstesting.NewClient() - svc.ServiceName = "elastictranscoder" - svc.APIVersion = "2012-09-25" +func BenchmarkRESTJSONRequest_Complex_CFCreateJob(b *testing.B) { + benchRESTJSONRequest(b, func() *request.Request { + req, _ := elastictranscoderSvc.CreateJobRequest(elastictranscoderCreateJobInput()) + return req + }) +} - params := &elastictranscoder.ListJobsByPipelineInput{ - PipelineId: aws.String("Id"), // Required - Ascending: aws.String("Ascending"), - PageToken: aws.String("Id"), - } +func BenchmarkRESTJSONRequest_Simple_ETCListJobsByPipeline(b *testing.B) { + benchRESTJSONRequest(b, func() *request.Request { + req, _ := elastictranscoderSvc.ListJobsByPipelineRequest(elastictranscoderListJobsByPipeline()) + return req + }) +} + +func benchRESTJSONBuild(b *testing.B, reqFn func() *request.Request) { + b.ResetTimer() for i := 0; i < b.N; i++ { - r := svc.NewRequest(&request.Operation{Name: "ListJobsByPipeline"}, params, nil) - restjson.Build(r) - if r.Error != nil { - b.Fatal("Unexpected error", r.Error) + req := reqFn() + restjson.Build(req) + if req.Error != nil { + b.Fatal("Unexpected error", req.Error) } } } -func BenchmarkRESTBuild_Simple_elastictranscoderListJobsByPipeline(b *testing.B) { - svc := awstesting.NewClient() - svc.ServiceName = "elastictranscoder" - svc.APIVersion = "2012-09-25" - - params := &elastictranscoder.ListJobsByPipelineInput{ - PipelineId: aws.String("Id"), // Required - Ascending: aws.String("Ascending"), - PageToken: aws.String("Id"), - } +func benchRESTJSONRequest(b *testing.B, reqFn func() *request.Request) { + b.ResetTimer() for i := 0; i < b.N; i++ { - r := svc.NewRequest(&request.Operation{Name: "ListJobsByPipeline"}, params, nil) - rest.Build(r) - if r.Error != nil { - b.Fatal("Unexpected error", r.Error) + err := reqFn().Send() + if err != nil { + b.Fatal("Unexpected error", err) } } } -func BenchmarkEncodingJSONMarshal_Simple_elastictranscoderListJobsByPipeline(b *testing.B) { - params := &elastictranscoder.ListJobsByPipelineInput{ +func elastictranscoderListJobsByPipeline() *elastictranscoder.ListJobsByPipelineInput { + return &elastictranscoder.ListJobsByPipelineInput{ PipelineId: aws.String("Id"), // Required Ascending: aws.String("Ascending"), PageToken: aws.String("Id"), } - - for i := 0; i < b.N; i++ { - buf := &bytes.Buffer{} - encoder := json.NewEncoder(buf) - if err := encoder.Encode(params); err != nil { - b.Fatal("Unexpected error", err) - } - } } -var restjsonBuildParms = &elastictranscoder.CreateJobInput{ - Input: &elastictranscoder.JobInput{ // Required - AspectRatio: aws.String("AspectRatio"), - Container: aws.String("JobContainer"), - DetectedProperties: &elastictranscoder.DetectedProperties{ - DurationMillis: aws.Int64(1), - FileSize: aws.Int64(1), - FrameRate: aws.String("FloatString"), - Height: aws.Int64(1), - Width: aws.Int64(1), - }, - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - FrameRate: aws.String("FrameRate"), - Interlaced: aws.String("Interlaced"), - Key: aws.String("Key"), - Resolution: aws.String("Resolution"), - }, - PipelineId: aws.String("Id"), // Required - Output: &elastictranscoder.CreateJobOutput{ - AlbumArt: &elastictranscoder.JobAlbumArt{ - Artwork: []*elastictranscoder.Artwork{ - { // Required - AlbumArtFormat: aws.String("JpgOrPng"), - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - InputKey: aws.String("WatermarkKey"), - MaxHeight: aws.String("DigitsOrAuto"), - MaxWidth: aws.String("DigitsOrAuto"), - PaddingPolicy: aws.String("PaddingPolicy"), - SizingPolicy: aws.String("SizingPolicy"), - }, - // More values... - }, - MergePolicy: aws.String("MergePolicy"), - }, - Captions: &elastictranscoder.Captions{ - CaptionFormats: []*elastictranscoder.CaptionFormat{ - { // Required - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - Format: aws.String("CaptionFormatFormat"), - Pattern: aws.String("CaptionFormatPattern"), - }, - // More values... - }, - CaptionSources: []*elastictranscoder.CaptionSource{ - { // Required - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - Key: aws.String("Key"), - Label: aws.String("Name"), - Language: aws.String("Key"), - TimeOffset: aws.String("TimeOffset"), - }, - // More values... - }, - MergePolicy: aws.String("CaptionMergePolicy"), - }, - Composition: []*elastictranscoder.Clip{ - { // Required - TimeSpan: &elastictranscoder.TimeSpan{ - Duration: aws.String("Time"), - StartTime: aws.String("Time"), - }, +func elastictranscoderCreateJobInput() *elastictranscoder.CreateJobInput { + return &elastictranscoder.CreateJobInput{ + Input: &elastictranscoder.JobInput{ // Required + AspectRatio: aws.String("AspectRatio"), + Container: aws.String("JobContainer"), + DetectedProperties: &elastictranscoder.DetectedProperties{ + DurationMillis: aws.Int64(1), + FileSize: aws.Int64(1), + FrameRate: aws.String("FloatString"), + Height: aws.Int64(1), + Width: aws.Int64(1), }, - // More values... - }, - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - Key: aws.String("Key"), - PresetId: aws.String("Id"), - Rotate: aws.String("Rotate"), - SegmentDuration: aws.String("FloatString"), - ThumbnailEncryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - ThumbnailPattern: aws.String("ThumbnailPattern"), - Watermarks: []*elastictranscoder.JobWatermark{ - { // Required - Encryption: &elastictranscoder.Encryption{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - Mode: aws.String("EncryptionMode"), - }, - InputKey: aws.String("WatermarkKey"), - PresetWatermarkId: aws.String("PresetWatermarkId"), + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), }, - // More values... + FrameRate: aws.String("FrameRate"), + Interlaced: aws.String("Interlaced"), + Key: aws.String("Key"), + Resolution: aws.String("Resolution"), }, - }, - OutputKeyPrefix: aws.String("Key"), - Outputs: []*elastictranscoder.CreateJobOutput{ - { // Required + PipelineId: aws.String("Id"), // Required + Output: &elastictranscoder.CreateJobOutput{ AlbumArt: &elastictranscoder.JobAlbumArt{ Artwork: []*elastictranscoder.Artwork{ { // Required @@ -320,37 +219,132 @@ var restjsonBuildParms = &elastictranscoder.CreateJobInput{ // More values... }, }, - // More values... - }, - Playlists: []*elastictranscoder.CreateJobPlaylist{ - { // Required - Format: aws.String("PlaylistFormat"), - HlsContentProtection: &elastictranscoder.HlsContentProtection{ - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("Base64EncodedString"), - KeyMd5: aws.String("Base64EncodedString"), - KeyStoragePolicy: aws.String("KeyStoragePolicy"), - LicenseAcquisitionUrl: aws.String("ZeroTo512String"), - Method: aws.String("HlsContentProtectionMethod"), - }, - Name: aws.String("Filename"), - OutputKeys: []*string{ - aws.String("Key"), // Required - // More values... + OutputKeyPrefix: aws.String("Key"), + Outputs: []*elastictranscoder.CreateJobOutput{ + { // Required + AlbumArt: &elastictranscoder.JobAlbumArt{ + Artwork: []*elastictranscoder.Artwork{ + { // Required + AlbumArtFormat: aws.String("JpgOrPng"), + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + InputKey: aws.String("WatermarkKey"), + MaxHeight: aws.String("DigitsOrAuto"), + MaxWidth: aws.String("DigitsOrAuto"), + PaddingPolicy: aws.String("PaddingPolicy"), + SizingPolicy: aws.String("SizingPolicy"), + }, + // More values... + }, + MergePolicy: aws.String("MergePolicy"), + }, + Captions: &elastictranscoder.Captions{ + CaptionFormats: []*elastictranscoder.CaptionFormat{ + { // Required + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + Format: aws.String("CaptionFormatFormat"), + Pattern: aws.String("CaptionFormatPattern"), + }, + // More values... + }, + CaptionSources: []*elastictranscoder.CaptionSource{ + { // Required + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + Key: aws.String("Key"), + Label: aws.String("Name"), + Language: aws.String("Key"), + TimeOffset: aws.String("TimeOffset"), + }, + // More values... + }, + MergePolicy: aws.String("CaptionMergePolicy"), + }, + Composition: []*elastictranscoder.Clip{ + { // Required + TimeSpan: &elastictranscoder.TimeSpan{ + Duration: aws.String("Time"), + StartTime: aws.String("Time"), + }, + }, + // More values... + }, + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + Key: aws.String("Key"), + PresetId: aws.String("Id"), + Rotate: aws.String("Rotate"), + SegmentDuration: aws.String("FloatString"), + ThumbnailEncryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + ThumbnailPattern: aws.String("ThumbnailPattern"), + Watermarks: []*elastictranscoder.JobWatermark{ + { // Required + Encryption: &elastictranscoder.Encryption{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + Mode: aws.String("EncryptionMode"), + }, + InputKey: aws.String("WatermarkKey"), + PresetWatermarkId: aws.String("PresetWatermarkId"), + }, + // More values... + }, }, - PlayReadyDrm: &elastictranscoder.PlayReadyDrm{ - Format: aws.String("PlayReadyDrmFormatString"), - InitializationVector: aws.String("ZeroTo255String"), - Key: aws.String("NonEmptyBase64EncodedString"), - KeyId: aws.String("KeyIdGuid"), - KeyMd5: aws.String("NonEmptyBase64EncodedString"), - LicenseAcquisitionUrl: aws.String("OneTo512String"), + // More values... + }, + Playlists: []*elastictranscoder.CreateJobPlaylist{ + { // Required + Format: aws.String("PlaylistFormat"), + HlsContentProtection: &elastictranscoder.HlsContentProtection{ + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("Base64EncodedString"), + KeyMd5: aws.String("Base64EncodedString"), + KeyStoragePolicy: aws.String("KeyStoragePolicy"), + LicenseAcquisitionUrl: aws.String("ZeroTo512String"), + Method: aws.String("HlsContentProtectionMethod"), + }, + Name: aws.String("Filename"), + OutputKeys: []*string{ + aws.String("Key"), // Required + // More values... + }, + PlayReadyDrm: &elastictranscoder.PlayReadyDrm{ + Format: aws.String("PlayReadyDrmFormatString"), + InitializationVector: aws.String("ZeroTo255String"), + Key: aws.String("NonEmptyBase64EncodedString"), + KeyId: aws.String("KeyIdGuid"), + KeyMd5: aws.String("NonEmptyBase64EncodedString"), + LicenseAcquisitionUrl: aws.String("OneTo512String"), + }, }, + // More values... + }, + UserMetadata: map[string]*string{ + "Key": aws.String("String"), // Required + // More values... }, - // More values... - }, - UserMetadata: map[string]*string{ - "Key": aws.String("String"), // Required - // More values... - }, + } } diff --git a/private/protocol/restxml/build_bench_test.go b/private/protocol/restxml/build_bench_test.go index 2736446a731..13106ee43b0 100644 --- a/private/protocol/restxml/build_bench_test.go +++ b/private/protocol/restxml/build_bench_test.go @@ -55,13 +55,6 @@ func BenchmarkRESTXMLBuild_Complex_CFCreateDistro(b *testing.B) { }) } -func BenchmarkRESTXMLRequest_Complex_CFCreateDistro(b *testing.B) { - benchRESTXMLRequest(b, func() *request.Request { - req, _ := cloudfrontSvc.CreateDistributionRequest(cloudfrontCreateDistributionInput()) - return req - }) -} - func BenchmarkRESTXMLBuild_Simple_CFDeleteDistro(b *testing.B) { params := cloudfrontDeleteDistributionInput() @@ -71,34 +64,41 @@ func BenchmarkRESTXMLBuild_Simple_CFDeleteDistro(b *testing.B) { }) } -func BenchmarkRESTXMLRequest_Simple_CFDeleteDistro(b *testing.B) { - benchRESTXMLRequest(b, func() *request.Request { - req, _ := cloudfrontSvc.DeleteDistributionRequest(cloudfrontDeleteDistributionInput()) +func BenchmarkRESTXMLBuild_REST_S3HeadObject(b *testing.B) { + params := s3HeadObjectInput() + + benchRESTXMLBuild(b, func() *request.Request { + req, _ := s3Svc.HeadObjectRequest(params) return req }) } -func BenchmarkRESTXMLBuild_REST_S3HeadObject(b *testing.B) { - params := s3HeadObjectInput() +func BenchmarkRESTXMLBuild_XML_S3PutObjectAcl(b *testing.B) { + params := s3PutObjectAclInput() benchRESTXMLBuild(b, func() *request.Request { - req, _ := s3Svc.HeadObjectRequest(params) + req, _ := s3Svc.PutObjectAclRequest(params) return req }) } -func BenchmarkRESTXMLRequest_REST_S3HeadObject(b *testing.B) { +func BenchmarkRESTXMLRequest_Complex_CFCreateDistro(b *testing.B) { benchRESTXMLRequest(b, func() *request.Request { - req, _ := s3Svc.HeadObjectRequest(s3HeadObjectInput()) + req, _ := cloudfrontSvc.CreateDistributionRequest(cloudfrontCreateDistributionInput()) return req }) } -func BenchmarkRESTXMLBuild_XML_S3PutObjectAcl(b *testing.B) { - params := s3PutObjectAclInput() +func BenchmarkRESTXMLRequest_Simple_CFDeleteDistro(b *testing.B) { + benchRESTXMLRequest(b, func() *request.Request { + req, _ := cloudfrontSvc.DeleteDistributionRequest(cloudfrontDeleteDistributionInput()) + return req + }) +} - benchRESTXMLBuild(b, func() *request.Request { - req, _ := s3Svc.PutObjectAclRequest(params) +func BenchmarkRESTXMLRequest_REST_S3HeadObject(b *testing.B) { + benchRESTXMLRequest(b, func() *request.Request { + req, _ := s3Svc.HeadObjectRequest(s3HeadObjectInput()) return req }) }