{"id":29978990,"url":"https://github.com/oagoulart/libluatsc","last_synced_at":"2026-04-16T17:41:29.498Z","repository":{"id":308049186,"uuid":"1031428487","full_name":"oAGoulart/libluatsc","owner":"oAGoulart","description":"Lua 5.4 library to read 64-bit time-stamp counter and TSC_AUX value.","archived":false,"fork":false,"pushed_at":"2025-08-03T19:41:52.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-03T21:25:16.868Z","etag":null,"topics":["lua","time-stamp-counter","tsc"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"ms-rl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oAGoulart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-03T18:05:56.000Z","updated_at":"2025-08-03T19:37:12.000Z","dependencies_parsed_at":"2025-08-03T21:25:22.360Z","dependency_job_id":"b67c5ab7-e506-43e6-977b-30e4eea26df2","html_url":"https://github.com/oAGoulart/libluatsc","commit_stats":null,"previous_names":["oagoulart/libluatsc"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/oAGoulart/libluatsc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oAGoulart%2Flibluatsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oAGoulart%2Flibluatsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oAGoulart%2Flibluatsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oAGoulart%2Flibluatsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oAGoulart","download_url":"https://codeload.github.com/oAGoulart/libluatsc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oAGoulart%2Flibluatsc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268697594,"owners_count":24292401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","time-stamp-counter","tsc"],"created_at":"2025-08-04T12:43:09.521Z","updated_at":"2026-04-16T17:41:29.487Z","avatar_url":"https://github.com/oAGoulart.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libluatsc\n\n[![GitHub Release](https://img.shields.io/github/v/release/oagoulart/libluatsc?color=green)](https://github.com/oAGoulart/libluatsc/releases)\n[![GitHub License](https://img.shields.io/github/license/oagoulart/libluatsc)](https://github.com/oAGoulart/libluatsc/tree/master?tab=MS-RL-1-ov-file)\n[![Static Badge](https://img.shields.io/badge/Lua-5.5-green?logo=lua)](https://www.lua.org/download.html)\n\nLua 5.5 library to read 64-bit time-stamp counter and `TSC_AUX` value.\n\n\u003e The TSC register can be used by performance-analysis applications, along with the performance\n\u003e monitoring registers, to help determine the relative frequency of an event or its duration.\n\u003e TSC is incremented at a rate corresponding to the baseline frequency of the processor\n\u003e (which may differ from actual processor frequency in low power modes of operation).\n\nSupports SSE 2 and if available will, by default:\n1. be executed only after all previous stores are globally visible; and\n2. be executed prior to execution of any subsequent instruction (including any memory accesses).\n\n## Usage\n\nBinaries for AMD64 are available on Releases page. For x86, build with `build.sh` script. If on Windows, use MinGW/MSYS2 with `CFLAGS` and `LFLAGS` set to include and library paths, respectively.\n\n```sh\nenv CFLAGS=-IC:/msys64/usr/local/include \\\n    LFLAGS=-LC:/msys64/usr/local/bin ./build.sh\n```\n\n**NOTE:** If you want to use MSVC, you are on your own, sorry.\n\nThen, require and call `now()` to get the counter and `TSC_AUX`. On most systems, `TSC_AUX` is initialized by privileged software with a signature value (e.g., a logical processor ID).\n\n```lua\nlocal tsc = require(\"libluatsc\")\n\nlocal stamp, aux = tsc.now()\nprint(\"stamp:\", stamp, \"aux:\", aux)\n\n--[[\n  The time stamp counter in newer processors may\n  support an enhancement, referred to as invariant TSC ]]--\nprint(\"is invariant?\", tsc.isinvariant())\n```\n\n...might output:\n\n```text\nstamp:  50806050955569   aux:   6\nis invariant?   true\n```\n\n**NOTE:** If the Lua code above fails with `module 'libluatsc' not found` on Windows, add `package.cpath=\".\\\\?.dll\"` one line before `require` or change your `LUA_CPATH` environment variable to include `.\\\\?.dll`.\n\n### Calculating delta time\n\nTo find the difference in seconds between two time stamps, you'll need to divide the result of T\u003csub\u003eend\u003c/sub\u003e minus T\u003csub\u003ebegin\u003c/sub\u003e by the the processor clock speed.\n\n```lua\nlocal tsc = require(\"libluatsc\")\n-- from: https://github.com/oAGoulart/libluacrc32\nlocal crc32 = require(\"libluacrc32\")\n\nlocal inp = assert(io.open(\"1MB.png\", \"rb\"))\nlocal data = inp:read(\"*all\")\nlocal dlen = string.len(data)\ninp:close()\n\nlocal begin, baux = tsc.now()\nlocal res = crc32.calculate(data, \"ISCSI\")\nlocal endin, eaux = tsc.now()\n\nos.execute(\"grep -m1 \\\"cpu MHz\\\" /proc/cpuinfo \u003e\u003e .cpuspd\")\nlocal cs = assert(io.open(\".cpuspd\", \"r\"))\nlocal result = cs:read(\"*a\")\ncs:close()\nlocal cpuspd = tonumber(result:match(\"%d+.%d+\"))\n\nlocal deltat = (endin - begin) / cpuspd\nprint(\"delta time:\", deltat, \"μs\", -- (MHz = 1e+6 = microsecond)\n      \"\\ndata length:\", dlen, \"bytes\",\n      \"\\nthroughput:\", dlen / deltat, \"MB/s\")\n```\n\n...might output:\n\n```text\ndelta time:     200.21097287982 μs\ndata length:    1066752 bytes\nthroughput:     5328.1395352907 MB/s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foagoulart%2Flibluatsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foagoulart%2Flibluatsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foagoulart%2Flibluatsc/lists"}