-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36d533d
commit 66f71d8
Showing
7 changed files
with
285 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
flags = -std=c++20 -isystem /usr/local/include -L/usr/local/lib -lpthread -lbenchmark_main -lbenchmark | ||
optflags = -flto -Ofast -DNDEBUG -march=native | ||
files = ada_benchmark.cpp | ||
|
||
all: gcc | ||
.PHONY: all | ||
|
||
gcc: $(files) | ||
g++ $(flags) $(optflags) $(files) | ||
|
||
clang: $(files) | ||
clang++ $(flags) $(optflags) $(files) | ||
|
||
gcc-noopt: $(files) | ||
g++ $(flags) $(files) | ||
|
||
clang-noopt: $(files) | ||
clang++ $(flags) $(files) | ||
|
||
gcc-profile-generate: $(files) | ||
g++ $(flags) $(optflags) -fprofile-generate $(files) | ||
|
||
clang-profile-generate: $(files) | ||
clang++ $(flags) $(optflags) -fprofile-generate $(files) | ||
|
||
gcc-profile-use: $(files) | ||
g++ $(flags) $(optflags) -fprofile-use $(files) | ||
|
||
clang-profile-use: $(files) | ||
clang++ $(flags) $(optflags) -fprofile-use $(files) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Ada URL vs Web++'s implementation of URL | ||
|
||
As of writing this, ada's url parser has more features than our implementation. In an effort to better our impl, we're | ||
going to benchmark our features against theirs. | ||
|
||
|
||
GCC: | ||
|
||
``` | ||
2023-10-07T07:33:24-08:00 | ||
Running ./a.out | ||
Run on (8 X 3176.74 MHz CPU s) | ||
CPU Caches: | ||
L1 Data 32 KiB (x4) | ||
L1 Instruction 32 KiB (x4) | ||
L2 Unified 256 KiB (x4) | ||
L3 Unified 6144 KiB (x1) | ||
Load Average: 2.37, 4.32, 4.17 | ||
---------------------------------------------------------- | ||
Benchmark Time CPU Iterations | ||
---------------------------------------------------------- | ||
WebppSchemePort 10.6 ns 10.5 ns 70043092 | ||
AdaSchemePort 12.6 ns 12.5 ns 46552076 | ||
``` | ||
|
||
Clang: | ||
|
||
``` | ||
2023-10-07T07:32:37-08:00 | ||
Load Average: 2.60, 4.65, 4.27 | ||
---------------------------------------------------------- | ||
Benchmark Time CPU Iterations | ||
---------------------------------------------------------- | ||
WebppSchemePort 6.24 ns 6.23 ns 115267454 | ||
AdaSchemePort 8.74 ns 8.67 ns 83124377 | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "../../webpp/std/string_view.hpp" | ||
#include "../benchmark.hpp" | ||
#include "./ada_scheme.hpp" | ||
#include "./webpp_scheme.hpp" | ||
|
||
using namespace webpp; | ||
|
||
|
||
static std::vector<std::string_view> schemes{{"one", | ||
"two", | ||
"three", | ||
"http", | ||
"five", | ||
"https", | ||
"https", | ||
"ftp", | ||
"ftps", | ||
"wss", | ||
"file", | ||
"ssh", | ||
"scheme", | ||
"nonsense", | ||
"", | ||
" ", | ||
"d;klasjfd;alsjf", | ||
"2408372-54", | ||
" @#$@fdsafd"}}; | ||
|
||
static void WebppSchemePort(benchmark::State& state) { | ||
std::size_t i = 0; | ||
for (auto _ : state) { | ||
auto scheme = schemes[i++ % schemes.size()]; | ||
benchmark::DoNotOptimize(scheme); | ||
auto w_scheme = webpp::v1::basic_scheme<std::string_view>{scheme}; | ||
auto port = w_scheme.known_port(); | ||
benchmark::DoNotOptimize(port); | ||
} | ||
} | ||
BENCHMARK(WebppSchemePort); | ||
|
||
|
||
static void AdaSchemePort(benchmark::State& state) { | ||
std::size_t i = 0; | ||
for (auto _ : state) { | ||
auto scheme = schemes[i++ % schemes.size()]; | ||
benchmark::DoNotOptimize(scheme); | ||
auto port = ada::scheme::get_special_port(scheme); | ||
benchmark::DoNotOptimize(port); | ||
} | ||
} | ||
BENCHMARK(AdaSchemePort); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Created by moisrex on 10/7/23. | ||
// source of this file: ada project / scheme-inl.h | ||
|
||
#ifndef WEBPP_ADA_SCHEME_HPP | ||
#define WEBPP_ADA_SCHEME_HPP | ||
|
||
#include <cstdint> | ||
#include <string_view> | ||
|
||
namespace ada::scheme { | ||
|
||
/** | ||
* @namespace ada::scheme::details | ||
* @brief Includes the definitions for scheme specific entities | ||
*/ | ||
namespace details { | ||
// for use with is_special and get_special_port | ||
// Spaces, if present, are removed from URL. | ||
constexpr std::string_view is_special_list[] = | ||
{"http", " ", "https", "ws", "ftp", "wss", "file", " "}; | ||
// for use with get_special_port | ||
constexpr uint16_t special_ports[] = {80, 0, 443, 80, 21, 443, 0, 0}; | ||
} // namespace details | ||
|
||
constexpr bool is_special(std::string_view scheme) { | ||
if (scheme.empty()) { | ||
return false; | ||
} | ||
int hash_value = (2 * scheme.size() + (unsigned) (scheme[0])) & 7; | ||
const std::string_view target = details::is_special_list[hash_value]; | ||
return (target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1)); | ||
} | ||
constexpr uint16_t get_special_port(std::string_view scheme) noexcept { | ||
if (scheme.empty()) { | ||
return 0; | ||
} | ||
int hash_value = (2 * scheme.size() + (unsigned) (scheme[0])) & 7; | ||
const std::string_view target = details::is_special_list[hash_value]; | ||
if ((target[0] == scheme[0]) && (target.substr(1) == scheme.substr(1))) { | ||
return details::special_ports[hash_value]; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
} // namespace ada::scheme | ||
|
||
#endif // WEBPP_ADA_SCHEME_HPP |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Created by moisrex on 10/7/23. | ||
|
||
#ifndef WEBPP_WEBPP_SCHEME_HPP | ||
#define WEBPP_WEBPP_SCHEME_HPP | ||
|
||
#include "../../webpp/std/string.hpp" | ||
#include "../../webpp/std/string_view.hpp" | ||
|
||
#include <cstdint> | ||
|
||
namespace webpp::v1 { | ||
|
||
template <typename StringType = stl::string> | ||
requires(istl::String<StringType> || istl::StringView<StringType>) | ||
struct basic_scheme : stl::remove_cvref_t<StringType> { | ||
using string_type = stl::remove_cvref_t<StringType>; | ||
|
||
template <typename... T> | ||
constexpr basic_scheme(T&&... args) : string_type{stl::forward<T>(args)...} {} | ||
|
||
|
||
|
||
/** | ||
* @brief checks if the URI is a relative reference | ||
*/ | ||
[[nodiscard]] constexpr bool is_relative_reference() const noexcept { | ||
return this->empty(); | ||
} | ||
|
||
/** | ||
* @return 0 if unknown, otherwise return the port | ||
*/ | ||
[[nodiscard]] constexpr stl::uint16_t known_port() const noexcept { | ||
// NOLINTBEGIN(*-avoid-magic-numbers) | ||
switch (this->size()) { | ||
case 2: | ||
if (this->operator[](0) == 'w' && this->operator[](1) == 's') | ||
return 80u; | ||
break; | ||
case 3: | ||
if (*this == "wss") | ||
return 443u; | ||
else if (*this == "ftp") | ||
return 21; | ||
break; | ||
case 4: | ||
if (*this == "http") | ||
return 80u; | ||
break; | ||
case 5: | ||
if (*this == "https") | ||
return 443; | ||
break; | ||
} | ||
return 0u; | ||
// NOLINTEND(*-avoid-magic-numbers) | ||
} | ||
}; | ||
|
||
} // namespace webpp::v1 | ||
|
||
#endif // WEBPP_WEBPP_SCHEME_HPP |
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
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