Fork me on GitHub
#beginners
<
2018-08-10
>
eggsyntax00:08:02

"If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is."

๐Ÿ˜„ 8
fabrao01:08:33

Hello all, is there any way having a number and verify some issues and stop flow if having problems, like in -> ? -> stock, verify with quantity of sales order, descrease stock, add quantity to sales order, if there is no stock, stop the main stream to be processed?

fabrao01:08:00

in clojure?

fabrao01:08:36

itยดs a pain doing this with many ifs

seancorfield01:08:21

some-> ... then if any part returns nil the whole pipeline stops.

jaihindhreddy-duplicate02:08:05

This one has been in the back of my mind for quite a while... How does one test code dealing with timeouts quickly? Mock timers/clocks that tick faster or is there something better?

noisesmith02:08:55

100ms is an eternity to the CPU

zooes03:08:39

Any pointers on how to debug a slow performing function?

zooes03:08:35

The code works, but takes about a second to solve for the 7 element vector, which is very poor compared to a similar solution in Java.

mfikes11:08:03

The code above runs in less than a millisecond for me for the 7-element vector.

eggsyntax13:08:27

@UC2B7D28Y are you perhaps including jvm/clj startup time in that one-second figure?

zooes15:08:07

@U077BEWNQ I am timing it using the (time) method just before calling the minimumSwaps() .. I need to figure out how 'time' calcs its elapsed time

eggsyntax15:08:07

Shouldn't be including startup time, then. I suspect something's weird with your setup, mfikes' time seems much more what I would expect.

zooes15:08:39

So, I was able to marginally optimize it, by using 'drop' (which returns a lazy sequence) over 'subvec' (returns a persistent vector).. I should maybe check my setup too.

eggsyntax16:08:50

My recommendation is to not even think about optimizing the code until you solve the setup problems. I just ran it in the REPL I happened to have open, & similar results to Mike:

user> (time (println (minimumSwaps [7 6 5 4 3 2 1])))
3
"Elapsed time: 1.254905 msecs"
nil

eggsyntax16:08:28

This isn't an issue with unoptimized code unless you're running on a box that's more than 15 years old ๐Ÿ˜‰

eggsyntax16:08:35

Maybe tell us how exactly you're loading and running it? Is this in a command-line clojure REPL? Or in some editor? Give us the details of your setup ๐Ÿ™‚

eggsyntax16:08:13

(also feel free to move it back to the main #beginners thread if you'd prefer; if nothing else, you might get faster responses)

zooes16:08:38

Thanks for the quick response @U077BEWNQ.. I am uploading my answers to HackerRank and the inputs on hacker rank have vector sizes of 100K & upwards. My performance problems are for larger data sets.

zooes16:08:13

My IDE is spacemacs and I am using CIDER REPL...

eggsyntax16:08:44

I also ran it in Spacemacs/CIDER. Something's definitely not right with your setup.

zooes17:08:57

OK, @U077BEWNQ ill check out a few things on my end

zooes17:08:46

@U077BEWNQ Ill move my question to the beginner thread. I implemented a similar solution in java and it performs better than the clojure code.. I wonder how I can optimize my coljure solution..

eggsyntax17:08:23

If it were me, I'd probably start by calling htop or top. I wonder if you've somehow got a bunch of orphaned JVM processes out there. I'd follow that with an emacs restart, and if that didn't work, a system reboot. Those three between them should identify or rule out the most likely problems. That said, I definitely hear that your broader question is about how to optimize the code, not about why it takes a full second to run, so I'll leave it at that.

zooes17:08:14

@U077BEWNQ - Thanks for the tips, trying them out now.

zooes03:08:40

I already tried providing the explicit types, but doesnt seem to make a difference

zooes03:08:24

I tried using transients, but has an open bug for subvec, that I am using in my solution- https://dev.clojure.org/jira/browse/CLJ-787

orestis05:08:30

@jaihindh.reddy I think tea-time might be helpful?

weihua11:08:59

hello, an editing related question, i've got a sexp (foo (bar a b c) d), now I only want (bar a b c), is there any paredit shortcut or something similar to help me delete outer stuff in one go?

dpsutton11:08:56

Put point on the opening paren and involve paredit raise sexp

weihua11:08:17

thanks @dpsutton... i was searching words like promote and cannot find anything, raise is the right word for it, ๐Ÿ˜„