我想打印每个t + dt方程组的解的执行时间,其中dt是.01秒
import { Button, Text, View } from 'react-native';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
<Button
title="Go to Settings"
onPress={() => this.props.navigation.navigate('Settings')}
/>
</View>
);
}
}
class SettingsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
</View>
);
}
}
由于我的时间间隔是.01(10/1000),从技术上讲,我应该有1000行输出语句,但由于某种原因,打印的行数要少得多。这根据设定的初始条件而变化。对于[0,0],大约打印10行。对于[1,2],大约有400行打印。我不明白为什么会这样。
答案 0 :(得分:0)
您正在做一些奇怪的事情,您正在测量ODE功能的执行时间。由于您的少数算术运算需要大约100个,最多几个1000个时钟周期,并且您的处理器每秒工作10 ^ 9个时钟周期,您的调用大约需要1到6秒,这在给定的输出格式中是看不到的。您有时会看到一些解释器开销和JIT编译时间。
odeint
使用内部自适应步长,请求的输出从内部步骤进行插值。内部步长可以小于输入时间阵列的时间步长,或者在诸如常数解决方案的钻孔解决方案的情况下,它可以非常大。 ODE功能仅在内部步骤调用,而不是在所有请求的输出时间调用。如果您将t
和z
添加到打印值,您会看到。
(0.0, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(1.221926641140105e-06, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(2.44385328228021e-06, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(0.01222171026468333, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(0.02444097667608438, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(0.03666024308748543, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(0.15885290720149592, array([ 0., 0.]), 'Execution took: 0:00:00.000010 secs (Wall clock time)')
(0.28104557131550645, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(0.403238235429517, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(1.625164876569622, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(2.8470915177097273, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(4.069018158849833, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')
(16.288284570250884, array([ 0., 0.]), 'Execution took: 0:00:00 secs (Wall clock time)')