示例#1
0
def GetFileSize(handle):
    size = wintypes.LARGE_INTEGER(0)

    res = win32api.GetFileSizeEx(handle, ctypes.byref(size))

    if not res:
        raise ctypes.WinError()

    return size.value
示例#2
0
 def wait_us(nanoseconds):
     """Wait for a specified number of nanoseconds."""
     wait_time = wintypes.LARGE_INTEGER(-abs(nanoseconds))
     timer_handle = _WIN32.CreateWaitableTimerW(None, True, None)
     if timer_handle == 0:
         raise Exception("CreateWaitableTimerW returned NULL")
     if _WIN32.SetWaitableTimer(timer_handle, byref(wait_time), 0, None,
                                None, False) == 0:
         raise Exception("SetWaitableTimer returned 0")
     _WIN32.WaitForSingleObject(timer_handle, _INFINITE)
     _WIN32.CloseHandle(timer_handle)
示例#3
0
def SetFilePointer(handle, offset,
                   moveMethod):  # we match the naming of pywin32

    newPos = wintypes.LARGE_INTEGER(5)

    res = win32api.SetFilePointerEx(handle, offset, ctypes.byref(newPos),
                                    moveMethod)

    if not res:
        raise ctypes.WinError()

    return newPos.value
示例#4
0
class LARGE_INTEGER(wintypes.LARGE_INTEGER):
    # https://msdn.microsoft.com/en-us/library/ff553204
    ntdll.RtlSecondsSince1970ToTime.restype = None
    _unix_epoch = wintypes.LARGE_INTEGER()
    ntdll.RtlSecondsSince1970ToTime(0, ctypes.byref(_unix_epoch))
    _unix_epoch = _unix_epoch.value

    def __int__(self):
        return self.value

    def __repr__(self):
        name = self.__class__.__name__
        return '%s(%d)' % (name, self.value)

    def as_time(self):
        time100ns = self.value - self._unix_epoch
        if time100ns >= 0:
            return time100ns / 1e7
        raise ValueError('value predates the Unix epoch')

    @classmethod
    def from_time(cls, t):
        time100ns = int(t * 10**7)
        return cls(time100ns + cls._unix_epoch)
示例#5
0
import math
from platform import system, release, version
from subprocess import check_output
from ctypes import WinDLL, wintypes, byref


# Imports kernel32.dll
kernel32 = WinDLL('kernel32', use_last_error=True)

starting_time = wintypes.LARGE_INTEGER()
ending_time = wintypes.LARGE_INTEGER()
elapsed_time = wintypes.LARGE_INTEGER()
frequency = wintypes.LARGE_INTEGER()

QueryPerformanceFrequency = kernel32.QueryPerformanceFrequency(byref(frequency))

# Upper limit for primes
pr = 8000000
OS = system()
Runs = []


# Main UI

class UI:
    Title = f"{85 * '-'}\n{35 * ' '}PYPrime 1.10 Windows{35 * ' '}\n{85 * '-'}\n\n"
    Description = '\nThis is a strictly single core benchmark. Please close all applications running in background to get the most reliable result\n'
    UserInput = f'{34 * "*"}\nPress ENTER to start the benchmark'
    ExitPrompt = 'Press ENTER to exit'
    InvalidExitPrompt = '\nInvalid run detected, press ENTER to exit'
    StartThing = 'Starting Benchmark...\n'