Test
This commit is contained in:
parent
6dd93155cc
commit
6e22717a81
8 changed files with 576 additions and 0 deletions
229
LSString/LSString.cpp
Normal file
229
LSString/LSString.cpp
Normal file
|
@ -0,0 +1,229 @@
|
|||
#include "LSString.h"
|
||||
#include <memory>
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
LSString::LSString(const char* pData)
|
||||
: m_uiLength(StringLength(pData))
|
||||
, m_uiCapacity(StringLength(pData))
|
||||
{
|
||||
if (!pData) return;
|
||||
|
||||
m_pData = new char[m_uiLength + 1];
|
||||
memset(m_pData, 0, m_uiLength + 1);
|
||||
memcpy(m_pData, pData, m_uiLength);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
LSString::LSString(const std::string& sRhs)
|
||||
: m_pData(new char[sRhs.length()])
|
||||
, m_uiLength(sRhs.length())
|
||||
, m_uiCapacity(sRhs.length())
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
LSString::LSString(const LSString& sRhs)
|
||||
: m_uiLength(sRhs.m_uiLength)
|
||||
, m_pData(new char[sRhs.m_uiLength + 1])
|
||||
, m_uiCapacity(sRhs.m_uiCapacity)
|
||||
{
|
||||
memset(m_pData + m_uiLength, 0, 1);
|
||||
memcpy(m_pData, sRhs.m_pData, m_uiLength);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
LSString::~LSString()
|
||||
{
|
||||
DELETE_ARRAY(m_pData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Insert(const LSString& sRhs, size_t uiPos)
|
||||
{
|
||||
Insert(sRhs.m_pData, uiPos);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Insert(const std::string& sRhs, size_t uiPos)
|
||||
{
|
||||
Insert(sRhs.c_str(), uiPos);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Insert(const char* pData, size_t uiPos)
|
||||
{
|
||||
if (!pData) return;
|
||||
|
||||
size_t uilength = StringLength(pData);
|
||||
size_t uiNewLength = m_uiLength + uilength;
|
||||
|
||||
while (uiNewLength > m_uiCapacity)
|
||||
{
|
||||
IncreaseCapacity(uiNewLength);
|
||||
}
|
||||
|
||||
char* pLeft = m_pData + uiPos;
|
||||
char* pRight = m_pData + uiPos + uilength;
|
||||
|
||||
memcpy(pRight, m_pData + uiPos, m_uiLength - uiPos);
|
||||
memcpy(pLeft, pData, uilength);
|
||||
|
||||
m_uiLength = uiNewLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Append(const LSString& sRhs)
|
||||
{
|
||||
Insert(sRhs, sRhs.Length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Append(const std::string& sRhs)
|
||||
{
|
||||
Insert(sRhs, sRhs.length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::Append(const char* pData)
|
||||
{
|
||||
Insert(pData, StringLength(pData));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Remove(const LSString& sRhs)
|
||||
{
|
||||
return RemoveAt(Find(sRhs), sRhs.m_uiLength);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Remove(const std::string& sRhs)
|
||||
{
|
||||
return RemoveAt(Find(sRhs), sRhs.length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Remove(const char* pData)
|
||||
{
|
||||
return RemoveAt(Find(pData), StringLength(pData));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::RemoveAt(size_t uiPos, size_t uiSize)
|
||||
{
|
||||
if (uiPos > m_uiLength) return false;
|
||||
|
||||
m_uiLength = m_uiLength - uiSize;
|
||||
char* pLast = m_pData + uiPos + uiSize;
|
||||
memcpy(m_pData + uiPos, pLast, uiSize);
|
||||
memset(pLast, 0, uiSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
size_t LSString::StringLength(const char* pChar) const
|
||||
{
|
||||
if (!pChar) return 0;
|
||||
int iRet = 0;
|
||||
while (*pChar != 0x0)
|
||||
{
|
||||
pChar++;
|
||||
iRet++;
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Contains(const LSString& sRhs) const
|
||||
{
|
||||
return Contains(sRhs.m_pData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Contains(const std::string& sRhs) const
|
||||
{
|
||||
return Contains(sRhs.c_str());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
bool LSString::Contains(const char* pData) const
|
||||
{
|
||||
int iRet = 1;
|
||||
size_t uiLength = StringLength(pData);
|
||||
size_t uiOffset = 0;
|
||||
|
||||
while (iRet != 0)
|
||||
{
|
||||
if (uiLength > m_uiLength || uiOffset > m_uiLength) break;
|
||||
iRet = memcmp(m_pData + uiOffset, pData, uiLength);
|
||||
uiOffset++;
|
||||
}
|
||||
|
||||
return iRet == 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
size_t LSString::Find(const LSString& sRhs, size_t uiOffset) const
|
||||
{
|
||||
return Find(sRhs.m_pData, uiOffset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
size_t LSString::Find(const std::string& sRhs, size_t uiOffset) const
|
||||
{
|
||||
return Find(sRhs.c_str(), uiOffset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
size_t LSString::Find(const char* pData, size_t uiOffset) const
|
||||
{
|
||||
size_t uiLength = StringLength(pData);
|
||||
size_t uiCurrentOffset = uiOffset;
|
||||
|
||||
for (int iRet = 1; iRet != 0; uiCurrentOffset++)
|
||||
{
|
||||
if (uiLength > m_uiLength || uiCurrentOffset > m_uiLength)
|
||||
{
|
||||
uiCurrentOffset = -1;
|
||||
break;
|
||||
}
|
||||
iRet = memcmp(m_pData + uiCurrentOffset, pData, uiLength);
|
||||
}
|
||||
|
||||
return uiCurrentOffset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
char LSString::At(size_t uiPos) const
|
||||
{
|
||||
return *(m_pData + uiPos);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
size_t LSString::Length() const
|
||||
{
|
||||
return m_uiLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
std::string LSString::ToStdString() const
|
||||
{
|
||||
return std::string(m_pData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
const char* LSString::ToCChar() const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void LSString::IncreaseCapacity(size_t uiNewLength)
|
||||
{
|
||||
m_uiCapacity = (m_uiCapacity + uiNewLength) * c_uiCapacityIncreaseFactor;
|
||||
char* pNew = new char[m_uiCapacity + 1];
|
||||
memset(pNew, 0, m_uiCapacity + 1);
|
||||
memcpy(pNew, m_pData, m_uiLength);
|
||||
DELETE_ARRAY(m_pData);
|
||||
m_pData = pNew;
|
||||
}
|
88
LSString/LSString.h
Normal file
88
LSString/LSString.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class LSString
|
||||
{
|
||||
private:
|
||||
#define DELETE_POINTER(Pointer) \
|
||||
if (Pointer != nullptr)\
|
||||
{\
|
||||
delete Pointer;\
|
||||
Pointer = nullptr;\
|
||||
}
|
||||
|
||||
#define DELETE_ARRAY(Array) \
|
||||
if (Array != nullptr)\
|
||||
{\
|
||||
delete[] Array;\
|
||||
Array = nullptr;\
|
||||
}
|
||||
|
||||
public:
|
||||
// - Constructor
|
||||
LSString() = default;
|
||||
|
||||
LSString(const char* pData);
|
||||
|
||||
LSString(const LSString& sRhs);
|
||||
|
||||
LSString(const std::string& sRhs);
|
||||
|
||||
LSString& operator=(const LSString& sRhs) = delete;
|
||||
|
||||
// - Destructor
|
||||
~LSString();
|
||||
|
||||
// - Alloc
|
||||
void Insert(const LSString& sRhs, size_t uiPos);
|
||||
|
||||
void Insert(const std::string& sRhs, size_t uiPos);
|
||||
|
||||
void Insert(const char* pData, size_t uiPos);
|
||||
|
||||
void Append(const LSString& sRhs);
|
||||
|
||||
void Append(const std::string& sRhs);
|
||||
|
||||
void Append(const char* pData);
|
||||
|
||||
bool Remove(const LSString& sRhs);
|
||||
|
||||
bool Remove(const std::string& sRhs);
|
||||
|
||||
bool Remove(const char* pData);
|
||||
|
||||
bool RemoveAt(size_t uiPos, size_t uiSize);
|
||||
|
||||
// - Utility
|
||||
size_t StringLength(const char* pData) const;
|
||||
|
||||
bool Contains(const LSString& sRhs) const;
|
||||
|
||||
bool Contains(const std::string& sRhs) const;
|
||||
|
||||
bool Contains(const char* pData) const;
|
||||
|
||||
size_t Find(const LSString& sRhs, size_t uiOffset = 0) const;
|
||||
|
||||
size_t Find(const std::string& sRhs, size_t uiOffset = 0) const;
|
||||
|
||||
size_t Find(const char* pData, size_t uiOffset = 0) const;
|
||||
|
||||
char At(size_t uiPos) const;
|
||||
|
||||
size_t Length() const;
|
||||
|
||||
std::string ToStdString() const;
|
||||
|
||||
const char* ToCChar() const;
|
||||
|
||||
private:
|
||||
|
||||
void IncreaseCapacity(size_t uiNewLength = 0);
|
||||
|
||||
char* m_pData = nullptr;
|
||||
size_t m_uiLength = 0;
|
||||
size_t m_uiCapacity = 0;
|
||||
const float c_uiCapacityIncreaseFactor = 1.5;
|
||||
};
|
166
LSString/LSString.vcxproj
Normal file
166
LSString/LSString.vcxproj
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{5FE98B77-3558-4384-BDAF-82AC8B69B752}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>String</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>LSString</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="LSString.cpp" />
|
||||
<ClCompile Include="Timer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="LSString.h" />
|
||||
<ClInclude Include="Timer.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
4
LSString/LSString.vcxproj.user
Normal file
4
LSString/LSString.vcxproj.user
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
20
LSString/Timer.cpp
Normal file
20
LSString/Timer.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "Timer.h"
|
||||
#include <iostream>
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
Timer::Timer()
|
||||
{
|
||||
m_StartTimePoint = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
Timer::~Timer()
|
||||
{
|
||||
auto endTimePoint = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimePoint).time_since_epoch().count();
|
||||
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count();
|
||||
|
||||
auto duration = end - start;
|
||||
std::cout << "Duration in Microseconds: " << duration << " (" << duration * 0.001 << " ms)" << std::endl;
|
||||
}
|
12
LSString/Timer.h
Normal file
12
LSString/Timer.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include <chrono>
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer(void);
|
||||
|
||||
~Timer(void);
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimePoint;
|
||||
};
|
26
LSString/main.cpp
Normal file
26
LSString/main.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <iostream>
|
||||
#include "LSString.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#define RUNS 50U
|
||||
#define PAYLOAD "187"
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("LSString:\n");
|
||||
printf("Number of runs: %d:\n", (int)RUNS);
|
||||
Timer ttt;
|
||||
for (size_t zRun = 1; zRun <= RUNS; zRun++)
|
||||
{
|
||||
printf("Run: %2d: ", (int)zRun);
|
||||
|
||||
Timer tt;
|
||||
LSString s("361");
|
||||
|
||||
for (size_t z = 0; z < RUNS * 187; z++)
|
||||
{
|
||||
s.Append(PAYLOAD);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue