# Negative Number of Inferences with time/1

**URL:** https://swi-prolog.discourse.group/t/negative-number-of-inferences-with-time-1/6691
**Category:** General
**Created:** [July 6, 2023, 8:14am UTC](https://swi-prolog.discourse.group/t/negative-number-of-inferences-with-time-1/6691 "2023-07-06T08:14:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![damiazz94](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@damiazz94](https://swi-prolog.discourse.group/u/damiazz94)
#### Post date: [July 6, 2023, 8:14am UTC](https://swi-prolog.discourse.group/t/negative-number-of-inferences-with-time-1/6691/1 "2023-07-06T08:14:44Z")

</div>

Hi,  
I’ve read this Prolog question on stackoverflow: [https://stackoverflow.com/questions/76615817/exponential-runtime-of-is-2-when-linear-would-suffice](https://stackoverflow.com/questions/76615817/exponential-runtime-of-is-2-when-linear-would-suffice)

By querying the example program with SWISH, time/1 prints a negative number of inferences.

```prolog
p(1).
p(X+X) :- p(X).

?- time(p(X)).
-2 inferences, 0.000 CPU in 0.000 seconds (87% CPU, -115433 Lips)
X = 1

```

How does time/1 works and how inferences are counted?

Thanks

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [July 6, 2023, 9:05am UTC](https://swi-prolog.discourse.group/t/negative-number-of-inferences-with-time-1/6691/2 "2023-07-06T09:05:08Z")

</div>

> [@damiazz94](#):
>
> How does [time/1](https://www.swi-prolog.org/pldoc/doc_for?object=time/1) works and how inferences are counted?

The VM counts inferences for calls and redo to normal Prolog predicates and foreign predicates except for those handled by the VM itself. The counts depend a bit on the running mode (debug, normal, optimized). Redo ports that should be counted in the theoretical model but are removed due to last call optimization are not in the counts. time/1 subtracts some inferences to compensate its overhead. The number subtracted seems a bit too high in this case.

The inference count has some value in the sense that low inferences per second suggest either the use of expensive foreign code (built-ins or user provided) or poor indexing.

Don’t trust the exact numbers 🙂
