Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/11/2023 in all areas

  1. gcue

    DateDiff_WorkDaysOnly

    Thought I'd share this snippet I created based off jdelaney's post Calculates date in the past based off of only work days (ie: a week of just workdays). Any feedback welcome $start_date = "2023/03/27" $weekdays_ago = 2 $date = DateDiff_WeekDaysOnly($start_date, $weekdays_ago) Func DateDiff_WeekDaysOnly($start_date, $weekdays_ago) $weekdays = 0 $days_reduce = 0 While $weekdays <> $weekdays_ago $days_reduce -= 1 $running_date = _DateAdd("d", $days_reduce, $start_date) $aTemp = StringSplit($running_date, "/") $iDate = _DateToDayOfWeek($aTemp[1], $aTemp[2], $aTemp[3]) If $iDate <> 1 And $iDate <> 7 Then $weekdays += 1 EndIf WEnd $date_desired = _DateAdd("d", $days_reduce, $start_date) Return $date_desired EndFunc ;==>DateDiff_WeekDaysOnly
    1 point
  2. How is this daunting? #include "C:\AutoIt\Eigen\Eigen4AutoIt.au3" ; NB adjust path to wherever you put it Local $embedding1[3] = [1.0, 2.0, 3.0] Local $embedding2[3] = [4.0, 5.0, 6.0] _Eigen_StartUp() $vec1=_Eigen_CreateMatrix_FromArray($embedding1) $vec2=_Eigen_CreateMatrix_FromArray($embedding2) MsgBox(0, "", "Cosine similarity: " & _ _Eigen_DotProduct($vec1,$vec2) / (_Eigen_GetNorm($vec1) * _Eigen_GetNorm($vec2))) _Eigen_CleanUp() (I don't have a CS background either.)
    1 point
  3. looks okay, but you should really look into E4A's DotProduct (section: Multiplication) and GetNorm (section: Reduction) functions.
    1 point
  4. Nine

    DateDiff_WorkDaysOnly

    Instead of counting every single days, it would be faster and somewhat more elegant to divide the number of working days into weeks and then only count the remaining few days : #include <Date.au3> Local $sDate = FastWorkDays(_NowDate(), -21) ConsoleWrite($sDate & @CRLF) Func FastWorkDays($sDate, $iNumDay) If Not $iNumDay Then Return SetError(1) Local $iSign = $iNumDay < 0 ? -1 : 1 Local $iNumWeek = Int(($iNumDay - $iSign) / 5) $iNumDay = Mod($iNumDay - $iSign, 5) + $iSign $sDate = _DateAdd("w", $iNumWeek, $sDate) Local $aTemp, $iDate While $iNumDay $sDate = _DateAdd("d", $iSign, $sDate) $aTemp = StringSplit($sDate, "/") $iDate = _DateToDayOfWeek($aTemp[1], $aTemp[2], $aTemp[3]) If $iDate = "1" Or $iDate = "7" Then ContinueLoop $iNumDay -= $iSign WEnd Return $sDate EndFunc
    1 point
  5. Using DllCallAddress() is even faster, but as the team said, it's only worth to optimize when you've got a lot of calls, normally the bottlenecks are somewhere else. I analyzed how many calls are made in SMF and switched to DllCallAddress() for some calls of which literally million of calls where made in huge and complex searches. Overall gain I would say is max 5 to 10% in speed, now the hardware itself seems to be the bottleneck and slowest part in searching for files. #include <WinAPISys.au3> $iTimer = TimerInit() For $i = 1 To 1000000 _WinAPI_GetTickCount64() Next ConsoleWrite(_WinAPI_GetTickCount64() & @CRLF) ConsoleWrite(TimerDiff($iTimer) & @CRLF & @CRLF) $iTimer = TimerInit() For $i = 1 To 1000000 DllCall('kernel32.dll', 'uint64', 'GetTickCount64') Next ConsoleWrite(DllCall('kernel32.dll', 'uint64', 'GetTickCount64')[0] & @CRLF) ConsoleWrite(TimerDiff($iTimer) & @CRLF & @CRLF) $iTimer = TimerInit() $dll = DllOpen("kernel32.dll") For $i = 1 To 1000000 DllCall($dll, 'uint64', 'GetTickCount64') Next ConsoleWrite(DllCall($dll, 'uint64', 'GetTickCount64')[0] & @CRLF) DllClose($dll) ConsoleWrite(TimerDiff($iTimer) & @CRLF & @CRLF) $iTimer = TimerInit() Global $hInstance_Kernel32_dll = _WinAPI_GetModuleHandle("kernel32.dll") Global $hAddress_Kernel32_dll_GetTickCount64 = _WinAPI_GetProcAddress($hInstance_Kernel32_dll, "GetTickCount64") For $i = 1 To 1000000 DllCallAddress('uint64', $hAddress_Kernel32_dll_GetTickCount64) Next ConsoleWrite(DllCallAddress('uint64', $hAddress_Kernel32_dll_GetTickCount64)[0] & @CRLF) ConsoleWrite(TimerDiff($iTimer) & @CRLF & @CRLF)
    1 point
×
×
  • Create New...