|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2026-Present Datadog, Inc. |
| 5 | + |
| 6 | +package parsing |
| 7 | + |
| 8 | +import ( |
| 9 | + "encoding/json" |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +var ( |
| 14 | + benchCloudWatch = json.RawMessage(`{"awslogs":{"data":"dGVzdA=="}}`) |
| 15 | + benchS3 = json.RawMessage(`{"Records":[{"eventSource":"aws:s3","s3":{"bucket":{"name":"b"},"object":{"key":"k"}}}]}`) |
| 16 | + benchSNSS3 = json.RawMessage(`{"Records":[{"EventSource":"aws:sns","Sns":{"Type":"Notification","Message":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b\"},\"object\":{\"key\":\"k\"}}}]}"}}]}`) |
| 17 | + benchSQSS3 = json.RawMessage(`{"Records":[` + |
| 18 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b1\"},\"object\":{\"key\":\"k1\"}}}]}"},` + |
| 19 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b2\"},\"object\":{\"key\":\"k2\"}}}]}"},` + |
| 20 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b3\"},\"object\":{\"key\":\"k3\"}}}]}"},` + |
| 21 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b4\"},\"object\":{\"key\":\"k4\"}}}]}"},` + |
| 22 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b5\"},\"object\":{\"key\":\"k5\"}}}]}"},` + |
| 23 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b6\"},\"object\":{\"key\":\"k6\"}}}]}"},` + |
| 24 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b7\"},\"object\":{\"key\":\"k7\"}}}]}"},` + |
| 25 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b8\"},\"object\":{\"key\":\"k8\"}}}]}"},` + |
| 26 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b9\"},\"object\":{\"key\":\"k9\"}}}]}"},` + |
| 27 | + `{"eventSource":"aws:sqs","body":"{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"b10\"},\"object\":{\"key\":\"k10\"}}}]}"}` + |
| 28 | + `]}`) |
| 29 | + benchSQSSNSS3 = json.RawMessage(`{"Records":[` + |
| 30 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b1\\\"},\\\"object\\\":{\\\"key\\\":\\\"k1\\\"}}}]}\"}"},` + |
| 31 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b2\\\"},\\\"object\\\":{\\\"key\\\":\\\"k2\\\"}}}]}\"}"},` + |
| 32 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b3\\\"},\\\"object\\\":{\\\"key\\\":\\\"k3\\\"}}}]}\"}"},` + |
| 33 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b4\\\"},\\\"object\\\":{\\\"key\\\":\\\"k4\\\"}}}]}\"}"},` + |
| 34 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b5\\\"},\\\"object\\\":{\\\"key\\\":\\\"k5\\\"}}}]}\"}"},` + |
| 35 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b6\\\"},\\\"object\\\":{\\\"key\\\":\\\"k6\\\"}}}]}\"}"},` + |
| 36 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b7\\\"},\\\"object\\\":{\\\"key\\\":\\\"k7\\\"}}}]}\"}"},` + |
| 37 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b8\\\"},\\\"object\\\":{\\\"key\\\":\\\"k8\\\"}}}]}\"}"},` + |
| 38 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b9\\\"},\\\"object\\\":{\\\"key\\\":\\\"k9\\\"}}}]}\"}"},` + |
| 39 | + `{"eventSource":"aws:sqs","body":"{\"Type\":\"Notification\",\"Message\":\"{\\\"Records\\\":[{\\\"s3\\\":{\\\"bucket\\\":{\\\"name\\\":\\\"b10\\\"},\\\"object\\\":{\\\"key\\\":\\\"k10\\\"}}}]}\"}"}` + |
| 40 | + `]}`) |
| 41 | + benchEventBridge = json.RawMessage(`{"version":"0","detail-type":"Object Created","source":"aws.s3","detail":{"bucket":{"name":"my-bucket"},"object":{"key":"my-key"}}}`) |
| 42 | +) |
| 43 | + |
| 44 | +func BenchmarkParse_Decoder_CloudWatch(b *testing.B) { |
| 45 | + b.ReportAllocs() |
| 46 | + for b.Loop() { |
| 47 | + _, _ = Parse(benchCloudWatch) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func BenchmarkParse_Unmarshal_CloudWatch(b *testing.B) { |
| 52 | + b.ReportAllocs() |
| 53 | + for b.Loop() { |
| 54 | + _, _ = ParseUnmarshal(benchCloudWatch) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +func BenchmarkParse_Decoder_S3(b *testing.B) { |
| 59 | + b.ReportAllocs() |
| 60 | + for b.Loop() { |
| 61 | + _, _ = Parse(benchS3) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +func BenchmarkParse_Unmarshal_S3(b *testing.B) { |
| 66 | + b.ReportAllocs() |
| 67 | + for b.Loop() { |
| 68 | + _, _ = ParseUnmarshal(benchS3) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +func BenchmarkParse_Decoder_SNS_S3(b *testing.B) { |
| 73 | + b.ReportAllocs() |
| 74 | + for b.Loop() { |
| 75 | + _, _ = Parse(benchSNSS3) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +func BenchmarkParse_Unmarshal_SNS_S3(b *testing.B) { |
| 80 | + b.ReportAllocs() |
| 81 | + for b.Loop() { |
| 82 | + _, _ = ParseUnmarshal(benchSNSS3) |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +func BenchmarkParse_Decoder_SQS_S3(b *testing.B) { |
| 87 | + b.ReportAllocs() |
| 88 | + for b.Loop() { |
| 89 | + _, _ = Parse(benchSQSS3) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +func BenchmarkParse_Unmarshal_SQS_S3(b *testing.B) { |
| 94 | + b.ReportAllocs() |
| 95 | + for b.Loop() { |
| 96 | + _, _ = ParseUnmarshal(benchSQSS3) |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +func BenchmarkParse_Decoder_SQS_SNS_S3(b *testing.B) { |
| 101 | + b.ReportAllocs() |
| 102 | + for b.Loop() { |
| 103 | + _, _ = Parse(benchSQSSNSS3) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +func BenchmarkParse_Unmarshal_SQS_SNS_S3(b *testing.B) { |
| 108 | + b.ReportAllocs() |
| 109 | + for b.Loop() { |
| 110 | + _, _ = ParseUnmarshal(benchSQSSNSS3) |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +func BenchmarkParse_Decoder_EventBridge(b *testing.B) { |
| 115 | + b.ReportAllocs() |
| 116 | + for b.Loop() { |
| 117 | + _, _ = Parse(benchEventBridge) |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +func BenchmarkParse_Unmarshal_EventBridge(b *testing.B) { |
| 122 | + b.ReportAllocs() |
| 123 | + for b.Loop() { |
| 124 | + _, _ = ParseUnmarshal(benchEventBridge) |
| 125 | + } |
| 126 | +} |
0 commit comments