// Copyright (c) 2020 Proton Technologies AG // // This file is part of ProtonMail Bridge. // // ProtonMail Bridge is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ProtonMail Bridge is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with ProtonMail Bridge. If not, see . package rfc5322 import ( "net/mail" "testing" ) func BenchmarkStandardSet(b *testing.B) { for i := 0; i < b.N; i++ { parseSet(benchStandardSet) } } func BenchmarkStandardSetGolang(b *testing.B) { for i := 0; i < b.N; i++ { parseSetGolang(benchStandardSet) } } func BenchmarkEncodedSet(b *testing.B) { for i := 0; i < b.N; i++ { parseSet(benchEncodedSet) } } func BenchmarkEncodedSetGolang(b *testing.B) { for i := 0; i < b.N; i++ { parseSetGolang(benchEncodedSet) } } func BenchmarkAddressListSet(b *testing.B) { for i := 0; i < b.N; i++ { parseSet(benchAddressListSet) } } func BenchmarkAddressListSetGolang(b *testing.B) { for i := 0; i < b.N; i++ { parseSetGolang(benchAddressListSet) } } func BenchmarkGroupSet(b *testing.B) { for i := 0; i < b.N; i++ { parseSet(benchGroupSet) } } func BenchmarkGroupSetGolang(b *testing.B) { for i := 0; i < b.N; i++ { parseSetGolang(benchGroupSet) } } func parseSet(set []string) { for _, addr := range set { _, _ = ParseAddressList(addr) } } func parseSetGolang(set []string) { for _, addr := range set { _, _ = mail.ParseAddressList(addr) } } var benchStandardSet = []string{ `user@example.com`, `John Doe `, `Mary Smith `, `"Joe Q. Public" `, `Mary Smith `, `jdoe@example.org`, `Who? `, ``, `"Giant; \"Big\" Box" `, `Pete `, `"Mary Smith: Personal Account" `, `Pete(A nice \) chap) `, `Gogh Fir `, `normal name `, `"comma, name" `, `name (ignore comment)`, `"Mail Robot" <>`, `Michal Hořejšek `, `First Last `, `First Last `, `First Last `, `First Last `, `First Last `, ``, `user@domain `, `First Last < user@domain.com>`, `First Middle @ Last `, `user@domain.com,`, `First Middle "Last" `, `First Middle Last `, `First Middle"Last" `, `First Middle "Last"`, `First "Middle" "Last" `, `First "Middle""Last" `, } var benchEncodedSet = []string{ `=?US-ASCII?Q?Keith_Moore?= `, `=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= `, `=?ISO-8859-1?Q?Andr=E9?= Pirard `, `=?ISO-8859-1?Q?Olle_J=E4rnefors?= `, `=?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= `, `Nathaniel Borenstein (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)`, `=?UTF-8?B?PEJlemUgam3DqW5hPg==?= `, `First Middle =?utf-8?Q?Last?= `, `First Middle =?utf-8?Q?Last?=`, `First =?utf-8?Q?Middle?= =?utf-8?Q?Last?= `, `First =?utf-8?Q?Middle?==?utf-8?Q?Last?= `, `First "Middle"=?utf-8?Q?Last?= `, `First "Middle" =?utf-8?Q?Last?= `, `First "Middle" =?utf-8?Q?Last?=`, `=?UTF-8?B?PEJlemUgam3DqW5hPg==?= `, `=?utf-8?B?6YCZ5piv5ryi5a2X55qE5LiA5YCL5L6L5a2Q?= `, `=?utf-8?B?8J+MmfCfjbc=?= `, `=?utf-8?B?8J+MmfCfjbc=?= `, } var benchAddressListSet = []string{ `Alice , Bob , Eve `, `Ed Jones ,joe@where.test,John `, `name (ignore comment) , (Comment as name) username2@server.com`, `"normal name" , "comma, name" `, `"comma, one" , "comma, two" `, `normal name , (comment)All.(around)address@(the)server.com`, `normal name , All.("comma, in comment")address@(the)server.com`, } var benchGroupSet = []string{ `A Group:Ed Jones ,joe@where.test,John ;`, `Undisclosed recipients:;`, `(Empty list)(start)Hidden recipients :(nobody(that I know)) ;`, }