How do I tell when I'm on Cygwin?

HighLine has some code like this:

begin
require “Win32API”

 if # I'm looking for the line that goes right here (see below).
   raise LoadError, "On Cygwin, not pure Windows."
 end

 # assume we're on Windows here...

rescue LoadError
# assume we’re on a Posix OS here…
end

The problem is that Cygwin is using the Windows code and the Posix
code would be a better choice there. What’s a test I can use to
detect Cygwin in this scenario?

James Edward G. II

On Wed, 25 Oct 2006, James Edward G. II wrote:

rescue LoadError

assume we’re on a Posix OS here…

end

The problem is that Cygwin is using the Windows code and the Posix code would
be a better choice there. What’s a test I can use to detect Cygwin in this
scenario?

James Edward G. II

posix = Process.fork{} and Process.wait rescue nil

-a

On 10/24/06, James Edward G. II [email protected] wrote:

 # assume we're on Windows here...

rescue LoadError
# assume we’re on a Posix OS here…
end

The problem is that Cygwin is using the Windows code and the Posix
code would be a better choice there. What’s a test I can use to
detect Cygwin in this scenario?

I /think/ RUBY_PLATFORM is different for cygwin than the pure windows
version, but I don’t have a cygwin install nearby to confirm. Perhaps

unless RUBY_PLATFORM =~ /mswin/
  raise LoadError, "..."
end

would work?

Cheers,
/Nick

On 10/24/06, [email protected] [email protected] wrote:

posix = Process.fork{} and Process.wait rescue nil

Everyone, please remember that Ara is kidding about this. Please do
not let this become an idiom.
The fact that the Win32 version of Ruby doesn’t support fork is a
temporary and unfortunate implementation detail, not something you can
rely on.

On Wed, 25 Oct 2006, Wilson B. wrote:

Everyone, please remember that Ara is kidding about this. Please do not let
this become an idiom. The fact that the Win32 version of Ruby doesn’t
support fork is a temporary and unfortunate implementation detail, not
something you can rely on.

you are spoiling all the fun!

:wink:

-a

On 10/24/06, Nick S. [email protected] wrote:

I /think/ RUBY_PLATFORM is different for cygwin than the pure windows
version, but I don’t have a cygwin install nearby to confirm. Perhaps

Via One click installer in regular windows:

irb(main):001:0> RUBY_PLATFORM
=> “i386-mswin32”

On CYGWIN:

irb(main):001:0> RUBY_PLATFORM
=> “i386-cygwin”

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

It’s easier even than that … just look up. If Austin Z. is
sneering at you, you’re on CygWin.

But that’s not true. You can get an identical scenario if you browse
to:
shootout.alioth.debian.org :slight_smile:

[email protected] wrote:

:wink:

-a

It’s easier even than that … just look up. If Austin Z. is
sneering at you, you’re on CygWin.

On Oct 24, 2006, at 1:40 PM, Gregory B. wrote:

irb(main):001:0> RUBY_PLATFORM
=> “i386-cygwin”

It seems safer to target this one as an exception, rather than mswin,
so I’ll go with that.

One last question though, if Termios was installed for Cygwin would
it work OK there? I’m trying to figure out if I need to bypass
HighLine’s search for that too.

Thanks for the help all.

James Edward G. II

Gregory B. wrote:

it work OK there? I’m trying to figure out if I need to bypass
HighLine’s search for that too.

I have no idea how to install termios for Cygwin since it’s not part
of the standard distribution (i don’t think), and I’m not really a
Cygwin user.

However, stty is included with Cygwin, so I think highline would work
using that.

Just about anything that will compile and execute on Linux will compile
and execute on CygWin. However, since the Ruby community has deprecated
CygWin, I’m not sure why new code should do other than detect it and
complain. :slight_smile:

When I run software on a Windows machine, my preference is for native
tools, with CygWin a “plan B” and a Gentoo virtual machine as “plan C”.

On 10/24/06, James Edward G. II removed_email_add[email protected] wrote:

HighLine’s search for that too.
I have no idea how to install termios for Cygwin since it’s not part
of the standard distribution (i don’t think), and I’m not really a
Cygwin user.

However, stty is included with Cygwin, so I think highline would work
using that.

[email protected] wrote:

On Wed, 25 Oct 2006, M. Edward (Ed) Borasky wrote:

However, since the Ruby community has deprecated
CygWin, I’m not sure why new code should do other than detect it and
complain. :slight_smile:

hi ed - what exactly do you mean by that?

-a
I’m not sure … I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

I’m not sure … I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

Hey, SHUT UP! :wink:

I think it’s just that One-Click installer is the preferred method and
is better supported. The philosophical arguments about Cygwin aside,
of course.

On Wed, 25 Oct 2006, M. Edward (Ed) Borasky wrote:

However, since the Ruby community has deprecated
CygWin, I’m not sure why new code should do other than detect it and
complain. :slight_smile:

hi ed - what exactly do you mean by that?

-a

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

I’m not sure … I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

The only real reason not to use it that I’m aware of is that it is
fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that’s not much of a selling point.

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

I’ve found this true before. The Cygwin version simply performs better
by a
significant margin than the one-click.

I will run some benchmarks again and post as well, as I don’t have the
old
figures handy.


Robert W. Oliver II
President, OCS Solutions, Inc. - Web Hosting and Development
http://www.ocssolutions.com/

Toll-Free Phone - 1-800-672-8415

OCS Ruby Forums - http://www.rubyforums.com/
My Blog - http://www.rwoliver.com/

Wilson B. wrote:

The only real reason not to use it that I’m aware of is that it is
fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that’s not much of a selling point.

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

Let me drag out my matrix benchmark and dual-booted (Win XP and Gentoo
Linux) Athlon XP laptop and see for myself!

Be back later, as they say in IRC!

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

Wilson B. wrote:

The only real reason not to use it that I’m aware of is that it is
fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that’s not much of a selling point.
Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

This is mostly because we’re not using the latest compiler. That’s one
reason I’ve been pushing so hard for the use of MSVC8 instead of
MSVC6. A MinGW compile is about 5 - 10% faster than the current MSVC6
(because even the slightly older GCC 3.x is a better compiler than the
many-years-old MSVC6). An MSVC8 compile would be up to 30% faster,
IIRC. I’d have to do some benchmarking, but I’m not on a Windows
machine with that right now.

-austin

On 10/24/06, Robert O. [email protected] wrote:

On 10/24/06, M. Edward (Ed) Borasky [email protected] wrote:

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?
I’ve found this true before. The Cygwin version simply performs better by a
significant margin than the one-click.

I will run some benchmarks again and post as well, as I don’t have the old
figures handy.

It’s not Cygwin that’s faster; it’s GCC. You’re comparing VC6 – which
is a compiler released in 1998 – to GCC 3.4.x released in 2004 or
later. Cygwin may be able to perform even faster, because it may
include GCC 4.x (I don’t know; I stopped using Cygwin as soon as I
found more useful tools that didn’t require the whole bloody
framework). Cygwin, on the other hand, will impose a certain amount of
overhead because everything essentially goes through the GPLed cygwin
DLL (and that licence choice, my friends, is part of the reason we
shouldn’t default to a Cygwin install in any case).

A MinGW build will perform faster than the VC6 build because of six
years of compiler optimizations applied – to compare apples to
apples, use GCC 2.8 or EGCS 1.1. I suspect that the performance of
Ruby compiled with GCC 2.8 would, well, suck. A VC8 build will perform
faster than either a MinGW build or a VC6 build – but there are other
tradeoffs that are turning out to be rather hard to deal with and
require assistance from Microsoft. To the limit of what compiler
optimizations make a difference, in any case.

I have little nice to say about Cygwin when people bring it up as a
solution, because it IS NOT a “solution” on Windows. It’s a hack; a
workaround. It’s good to use when you absolutely must use Unix
software that the developers have been too damned lazy to actually
port the software to Windows. It’s really not much better than using
WINE to run Windows software. It’ll work, but that doesn’t mean you
really want to use it if you don’t absolutely have to.

Please, try to compare apples to apples.

If Matz, as usual, has a 1.8.6 release for Christmas (Matz?) I will be
recommending Curt use MinGW to compile Ruby for Windows. The
discussions that are going on with Microsoft will be continuing with
the preferred target for the VC8 build being next year’s 1.9.1,
because I suspect it will take nearly that long to build the support
tools we need to make this work properly.

-austin

Here’s my results:

The native Ruby (one-click):

E:>ruby benchmark.rb
Start Ruby benchmark
user system total real
intArithmetic i:10000001
intResult:1
8.890000 0.000000 8.890000 ( 9.078000)
doubleArithmetic i:11000000.0
doubleResult:10011632.7168688
1.235000 0.000000 1.235000 ( 1.390000)
longArithmetic i:11000000
Result:10000000
2.562000 0.015000 2.577000 ( 2.735000)
trig i:100000.0
sine:0.860248280789742
cosine:-0.509875372417901
tangent:-1.68717362580256
logarithm:4.99999565703347
squareRoot:316.226184874055
0.547000 0.000000 0.547000 ( 0.546000)
io write=10000 read=10000 0.047000 0.016000 0.063000 (
0.079000)
Total Ruby benchmark time: 13.281000 0.031000 13.312000 ( 13.828000)

The Cygwin Ruby:

$ ruby benchmark.rb
Start Ruby benchmark
user system total real
intArithmetic i:10000001
intResult:1
5.875000 0.000000 5.875000 ( 5.904000)
doubleArithmetic i:11000000.0
doubleResult:10011632.7168688
0.844000 0.000000 0.844000 ( 0.844000)
longArithmetic i:11000000
Result:10000000
1.515000 0.000000 1.515000 ( 1.538000)
trig i:100000.0
sine:0.860248280789742
cosine:-0.509875372417901
tangent:-1.68717362580256
logarithm:4.99999565703347
squareRoot:316.226184874055
0.360000 0.000000 0.360000 ( 0.399000)
io write=10000 read=10000 0.015000 0.032000 0.047000 (
0.051000)
Total Ruby benchmark time: 8.609000 0.032000 8.641000 ( 8.736000)

The benchmark code (I would love to credit the person who wrote this,
but
I’ve had it for quite some time and don’t remember where I found it):

#! /usr/bin/ruby

require “benchmark”
include Benchmark

intMax = 10000000000 # 1B
doubleMin = 10000000000.0 # 10B
doubleMax = 11000000000.0 # 11B
longMin = 10000000000 # 10B
longMax = 11000000000 # 11B
trigMax = 10000000.0 # 10M
ioMax = 1000000 # 1M

I used these numbers to test as the orig. ones take too long

intMax = 10000000 # 1B
doubleMin = 10000000.0 # 10B
doubleMax = 11000000.0 # 11B
longMin = 10000000 # 10B
longMax = 11000000 # 11B
trigMax = 100000.0 # 10M
ioMax = 10000 # 1M

def intArithmetic(intMax)

i = 1
intResult = 1
while i < intMax
    intResult = intResult - i
    i = i + 1
    intResult = intResult + i
    i = i + 1
    intResult = intResult * i
    i = i + 1
    intResult = intResult / i
    i = i + 1
end
print " i:", i, "\n"
print " intResult:", intResult, "\n"

end

def doubleArithmetic(doubleMin, doubleMax)

i = doubleMin
doubleResult = doubleMin
while i < doubleMax
    doubleResult = doubleResult - i
    i = i + 1.0
    doubleResult = doubleResult + i
    i = i + 1.0
    doubleResult = doubleResult * i
    i = i + 1.0
    doubleResult = doubleResult / i
    i = i + 1.0
end
print " i:", i, "\n"
print " doubleResult:", doubleResult, "\n"

end

def longArithmetic(longMin, longMax)

i = longMin
longResult = longMin
while i < longMax
    longResult = longResult - i
    i = i + 1
    longResult = longResult + i
    i = i + 1
    longResult = longResult * i
    i = i + 1
    longResult = longResult / i
    i = i + 1
end
print " i:", i, "\n"
print " Result:", longResult, "\n"

end

def trig(trigMax)
i = 1.0
sine = 0.0
cosine = 0.0
tangent = 0.0
logarithm = 0.0
squareRoot = 0.0

while i < trigMax
    sine = Math.sin(i)
    cosine = Math.cos(i)
    tangent = Math.tan(i)
    logarithm = Math.log10(i)
    squareRoot = Math.sqrt(i)
    i = i + 1.0
end
print " i:", i, "\n"
print " sine:", sine, "\n"
print " cosine:", cosine, "\n"
print " tangent:", tangent, "\n"
print " logarithm:", logarithm, "\n"
print " squareRoot:", squareRoot, "\n"

end

def io(ioMax)
fileName = “TestRuby.txt”
myString =
“abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefgh\n”

linesToWrite = [myString]
for i in 2…ioMax
linesToWrite.push( myString )
end

file = File.open(fileName, ‘w’)
file.puts(linesToWrite)
file.close()

file = File.open(fileName, ‘r’)
readLines = file.readlines()
file.close()
print “write=”,linesToWrite.length()
print " read=",readLines.length()
end

Main program begins here

puts “Start Ruby benchmark”

t = 0
benchmark(" " + CAPTION, 7, FMTSTR) do |x|
t = x.report(“intArithmetic”) { intArithmetic(intMax) }
t += x.report(“doubleArithmetic”) { doubleArithmetic(doubleMin,
doubleMax) }
t += x.report(“longArithmetic”) { longArithmetic(longMin, longMax)
}
t += x.report(“trig”) { trig(trigMax) }
t += x.report(“io”) { ioTime = io(ioMax) }
end

print “Total Ruby benchmark time:”, t, “\n”
puts “End Ruby benchmark”

On my computer, Cygwin’s Ruby was almost twice as fast.

On 10/24/06, Robert O. [email protected] wrote:

Robert W. Oliver II
President, OCS Solutions, Inc. - Web Hosting and Development
http://www.ocssolutions.com/

Toll-Free Phone - 1-800-672-8415

OCS Ruby Forums - http://www.rubyforums.com/
My Blog - http://www.rwoliver.com/


Robert W. Oliver II
President, OCS Solutions, Inc. - Web Hosting and Development
http://www.ocssolutions.com/

Toll-Free Phone - 1-800-672-8415

OCS Ruby Forums - http://www.rubyforums.com/
My Blog - http://www.rwoliver.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs