timing

Could a random sleep prevent timing attacks?

有些话、适合烂在心里 提交于 2019-11-29 17:47:55
问题 From Wikipedia In cryptography, a timing attack is a side channel attack in which the attacker attempts to compromise a cryptosystem by analyzing the time taken to execute cryptographic algorithms. Actually, to prevent timing attacks, I'm using the following function taken from this answer: function timingSafeCompare($safe, $user) { // Prevent issues if string length is 0 $safe .= chr(0); $user .= chr(0); $safeLen = strlen($safe); $userLen = strlen($user); // Set the result to the difference

How can I find the execution time of a section of my program in C?

£可爱£侵袭症+ 提交于 2019-11-29 11:31:45
问题 I'm trying to find a way to get the execution time of a section of code in C. I've already tried both time() and clock() from time.h, but it seems that time() returns seconds and clock() seems to give me milliseconds (or centiseconds?) I would like something more precise though. Is there a way I can grab the time with at least microsecond precision? This only needs to be able to compile on Linux. 回答1: You referred to clock() and time() - were you looking for gettimeofday() ? That will fill in

Input with a timeout in C++

微笑、不失礼 提交于 2019-11-29 07:35:58
I want to have a program where the user have 10 seconds to enter the password. If the timer goes over 10 seconds, the program displays a message. My current code is this: #include <iostream> #include <ctime> #include <string> int main(){ std::string password; int start_s=clock(); int stop_s=clock(); if(stop_s-start_s <= 0){ std::cout << "TIME RAN OUT!"; } std::cout << "Enter your password! \n"; std::cout << "Password: "; std::cin >> password; std::cout << "\n \n"; if (password == "password123"){ std::cout << "Correct!"; } else { std::cout << "Wrong!"; } } This of course is not working... But I

How to realise long-term high-resolution timing on windows using C++?

有些话、适合烂在心里 提交于 2019-11-29 07:26:19
I need to get exact timestamps every couple of ms (20, 30, 40ms) over a long period of time (a couple of hours). The function in which the timestamp is taken is invoked as a callback by a 3rd-party library. Using GetSystemTime() one can get the correct system timestamp but only with milliseconds accuracy, which is not precise enough for me. Using QueryPerformanceTimer() yields more accurate timestamps but is not synchronous to the system timestamp over a long period of time (see http://msdn.microsoft.com/en-us/magazine/cc163996.aspx ). The solution provided at the site linked above somehow

Executing code at regularly timed intervals in Clojure

北城以北 提交于 2019-11-29 06:17:40
问题 What's the best way to make code run at regular intervals in Clojure ? I'm currently using java.util.concurrent.ScheduledExecutorService, but that's Java - is there a Clojure way of scheduling code to run at regular intervals, after a delay, cancellably ? All the Clojure code examples I've seen use Thread/sleep, which also seems too Java. 回答1: Well worth looking at the source code for Overtone, in particular the code for scheduling events at a particular time. It's a music synthesis system so

How to time a function in milliseconds without boost::timer

若如初见. 提交于 2019-11-29 05:13:47
问题 I am using boost 1.46 which does not include boost::timer, What other way can I time my functions. I am currently doing this: time_t now = time(0); <some stuff> time_t after = time(0); cout << after - now << endl; but it just gives the answer in seconds, so if the function takes < 1s it displays 0. Thanks 回答1: In linux or Windows: #include <ctime> #include <iostream> int main(int, const char**) { std::clock_t start; start = std::clock(); // your test std::cout << "Time: " << (std::clock() -

Timing in JS - multiple setIntervals running at once and starting at the same time?

穿精又带淫゛_ 提交于 2019-11-29 02:02:37
问题 Let's say I have a function: myFunc = function(number) { console.log("Booyah! "+number); } And I want it to run on a set interval. Sounds like I should use setInterval, huh! But what if I want to run multiple intervals of the same function, all starting at the exact same time? setInterval(function(){ myFunc(1); }, 500); setInterval(function(){ myFunc(2); }, 1000); setInterval(function(){ myFunc(3); }, 2000); So that the first runs exactly twice in the time it takes the second to run once, and

What does CPU Time for a Hadoop Job signify?

為{幸葍}努か 提交于 2019-11-29 00:16:16
I am afraid I do not understand the timing results of a Map-Reduce job. For example, a job I am running gives me the following results from the job tracker. Finished in: 1mins, 39sec CPU time spent (ms) 150,460 152,030 302,490 The entries in CPU time spent (ms) are for Map, Reduce and Total respectively. But, then how is "CPU time spent" being measured and what does it signify? Is this the total cumulative time spent in each of the mappers and reducers assigned for the job? Is it possible to measure other times from the framework such as time for shuffle, sort, partition etc? If so, how? A

How can we easily time function calls in elixir?

扶醉桌前 提交于 2019-11-28 22:16:53
问题 How can we easily time function calls in Elixir? Is there any hidden switch in IEx to enable this? 回答1: You can write a module 1 that can measure a given function. The following function returns the runtime of a given function in seconds: defmodule Benchmark do def measure(function) do function |> :timer.tc |> elem(0) |> Kernel./(1_000_000) end end Use it like this: iex> Benchmark.measure(fn -> 123456*654321 end) 9.0e-6 If you want to use that for Benchmarking, then there is another answer. A

Microsecond accurate (or better) process timing in Linux

安稳与你 提交于 2019-11-28 20:45:51
I need a very accurate way to time parts of my program. I could use the regular high-resolution clock for this, but that will return wallclock time, which is not what I need: I needthe time spent running only my process. I distinctly remember seeing a Linux kernel patch that would allow me to time my processes to nanosecond accuracy, except I forgot to bookmark it and I forgot the name of the patch as well :(. I remember how it works though: On every context switch, it will read out the value of a high-resolution clock, and add the delta of the last two values to the process time of the