Skip to content

Commit 7c3f57a

Browse files
committed
性能测试
1 parent 4443a87 commit 7c3f57a

File tree

9 files changed

+141932
-6
lines changed

9 files changed

+141932
-6
lines changed

CodeFormatServer/src/CodeFormatServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
2020
if (argc > 1)
2121
{
2222
int port = std::stoi(argv[1]);
23-
tcp::acceptor acceptor(*ioc, tcp::endpoint(tcp::v4(), port));
23+
tcp::acceptor acceptor(ioc, tcp::endpoint(tcp::v4(), port));
2424

2525
auto socket = acceptor.accept();
2626
LanguageClient::GetInstance().SetSession(std::make_shared<SocketIOSession>(std::move(socket)));
@@ -31,5 +31,5 @@ int main(int argc, char** argv)
3131
LanguageClient::GetInstance().SetSession(std::make_shared<StandardIOSession>());
3232
}
3333

34-
return LanguageClient::GetInstance().Run(ioc);
34+
return LanguageClient::GetInstance().Run();
3535
}

CodeFormatServer/src/Session/IOSession.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CodeFormatServer/Session/IOSession.h"
1+
#include "CodeFormatServer/Session/IOSession.h"
22
#include <iostream>
33
#include <nlohmann/json.hpp>
44
#include "CodeFormatServer/Protocol/ProtocolParser.h"
@@ -29,7 +29,7 @@ IOSession::~IOSession()
2929

3030
int IOSession::Run(asio::io_context& ioc)
3131
{
32-
//Æ»¹ûÔÝδ֧³Ö Õâ¸öjthread
32+
//苹果暂未支持 这个jthread
3333
#ifndef __APPLE__
3434
_logicThread = std::make_shared<std::jthread>([&ioc](std::stop_token st)
3535
{

LuaParser/src/LuaParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void LuaParser::BuildAst()
4545
{
4646
Block(_chunkAstNode);
4747
}
48-
catch (LuaParseException& e)
48+
catch (LuaParseException&)
4949
{
5050
// ignore
5151
}
@@ -111,7 +111,6 @@ void LuaParser::SetFilename(std::string_view filename)
111111
std::filesystem::path path(filename);
112112
_file->SetFilename(path.replace_extension().string());
113113
#endif
114-
115114
}
116115

117116
std::string_view LuaParser::GetFilename()

Test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ target_link_libraries(CodeFormatTest CodeService Util)
2121
add_test(NAME GrammarTest COMMAND CodeFormatTest CheckGrammar -w ${CodeFormatTest_SOURCE_DIR}/test_script/grammar)
2222
add_test(NAME FormatTest COMMAND CodeFormatTest CheckFormatResult -w ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format -f ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format_should_be)
2323
add_test(NAME FormatByOptionTest COMMAND CodeFormatTest CheckFormatResultByOption -w ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format_by_option -f ${CodeFormatTest_SOURCE_DIR}/test_script/format_text/wait_format_by_option_should_be)
24+
add_test(NAME FormatPerformance COMMAND CodeFormatTest Performance -w ${CodeFormatTest_SOURCE_DIR}/test_script/performance)

Test/src/CodeFormatTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include <filesystem>
44
#include <vector>
55
#include <fstream>
6+
#include <chrono>
67
#include "CodeService/LuaFormatter.h"
78
#include "Util/format.h"
89
#include "Util/CommandLine.h"
910
#include "Util/StringUtil.h"
1011
#include "CodeService/LuaEditorConfig.h"
1112

13+
using namespace std::chrono;
1214

1315
bool TestFormatted(std::string input, const std::string& shouldBe, std::shared_ptr<LuaCodeStyleOptions> options)
1416
{
@@ -24,6 +26,21 @@ bool TestFormatted(std::string input, const std::string& shouldBe, std::shared_p
2426
return StringUtil::TrimSpace(formattedText) == StringUtil::TrimSpace(shouldBe);
2527
}
2628

29+
uint64_t TestPerformance(std::string input, std::shared_ptr<LuaCodeStyleOptions> options)
30+
{
31+
auto start = steady_clock::now();
32+
auto parser = LuaParser::LoadFromBuffer(std::move(input));
33+
parser->BuildAstWithComment();
34+
35+
LuaFormatter formatter(parser, *options);
36+
37+
formatter.BuildFormattedElement();
38+
39+
volatile auto formattedText = formatter.GetFormattedText();
40+
41+
return duration_cast<milliseconds>(steady_clock::now() - start).count();
42+
}
43+
2744
bool TestGrammar(std::string input)
2845
{
2946
auto parser = LuaParser::LoadFromBuffer(std::move(input));
@@ -114,6 +131,7 @@ int main(int argc, char* argv[])
114131
commandLine.AddTarget("CheckGrammar");
115132
commandLine.AddTarget("CheckFormatResult");
116133
commandLine.AddTarget("CheckFormatResultByOption");
134+
commandLine.AddTarget("Performance");
117135

118136
commandLine.Add<std::string>("work-directory", "w", "special base work directory");
119137
commandLine.Add<std::string>("formatted-work-directory", "f", "special formatted work directory");
@@ -206,6 +224,21 @@ int main(int argc, char* argv[])
206224
std::cout << format("test check grammar {} ... {}", path, passed ? "passed" : "false") << std::endl;
207225
}
208226
}
227+
else if(target == "Performance")
228+
{
229+
auto options = std::make_shared<LuaCodeStyleOptions>();
230+
#ifndef _WIN32
231+
options->end_of_line = "\n";
232+
#endif
233+
for (auto& path : luaFiles)
234+
{
235+
auto waitFormattingFilePath = workRoot / path;
236+
auto waitFormattingText = ReadFile(waitFormattingFilePath.string());
237+
238+
auto time = TestPerformance(waitFormattingText, options);
239+
std::cout << format("test format Performance {} ...it cost {}ms", path, time ) << std::endl;
240+
}
241+
}
209242

210243

211244
return success ? 0 : -1;

0 commit comments

Comments
 (0)