본문 바로가기
프로그래밍/C#

ObscuredString / String 을 숫자로 변환 했을 때의 성능

by neive 2022. 3. 4.
728x90
using System.Diagnostics;
using System.Numerics;
using CodeStage.AntiCheat.ObscuredTypes;
using UnityEngine;
using Debug = UnityEngine.Debug;

public class Test_Obscured : MonoBehaviour
{
    private BigInteger m_Value1 = 100000;
    private BigInteger m_Value2 = 1000;
    private ObscuredString m_ObsValue1 = "100000";
    private ObscuredString m_ObsValue2 = "1000";
    private string m_StrValue1 = "100000";
    private string m_StrValue2 = "1000";
    
    private void Start()
    {
        var watch = new Stopwatch();
        
        
        
        watch.Start();

        BigInteger tmp1;
        for (var i=0; i<10000; i++)
            tmp1 = m_Value1 + m_Value2;
        
        watch.Stop();
        Debug.Log($"Value Time {watch.ElapsedMilliseconds}/1000 sec");
        
        
        
        watch.Restart();

        BigInteger tmp2;
        for (var i=0; i<10000; i++)
            tmp2 = BigInteger.Parse(m_ObsValue1) + BigInteger.Parse(m_ObsValue2);
        
        watch.Stop();
        Debug.Log($"ObsValue Time {watch.ElapsedMilliseconds}/1000 sec");
        
        
        
                
        watch.Restart();

        BigInteger tmp3;
        for (var i=0; i<10000; i++)
            tmp3 = BigInteger.Parse(m_StrValue1) + BigInteger.Parse(m_StrValue2);
        
        watch.Stop();
        Debug.Log($"StrValue Time {watch.ElapsedMilliseconds}/1000 sec");
    }
}

 

 

일반 스트링 대비 50% 느리지만 만번 돌려서 0.035초니까 이것 때문에 엄청 느려지진 않을 것 같다는 생각이네요

 

728x90

댓글