Skip to content

Commit 8dae08f

Browse files
committed
sin cpu
1 parent 680f18a commit 8dae08f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ch01_basic/at015_sincpu.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
# at015_sincpu: CPU正弦曲线
4+
"""
5+
Topic: sample
6+
Desc : CPU正弦曲线
7+
"""
8+
import itertools, math, time, sys
9+
10+
__author__ = 'Xiong Neng'
11+
12+
time_period = float(sys.argv[1]) if len(sys.argv) > 1 else 60 # seconds
13+
time_slice = float(sys.argv[2]) if len(sys.argv) > 2 else 0.04 # seconds
14+
15+
N = int(time_period / time_slice)
16+
for i in itertools.cycle(range(N)):
17+
busy_time = time_slice / 2 * (math.sin(2 * math.pi * i / N) + 1)
18+
t = time.clock() + busy_time
19+
while t > time.clock():
20+
pass
21+
time.sleep(time_slice - busy_time)

0 commit comments

Comments
 (0)